|
Boost : |
From: Thomas Wenisch (twenisch_at_[hidden])
Date: 2003-07-07 13:21:34
Hi,
for_each seems to be unable to deal with empty lists, or lists that
are built by push_front on an empty list. However, vectors work
fine. Here is code which demonstrates the problem. Replacing list with
vector makes the code compile.
#include <iostream>
#include <boost/static_assert.hpp>
#include <boost/mpl/push_front.hpp>
#include <boost/mpl/list.hpp>
#include <boost/mpl/size.hpp>
#include <boost/mpl/for_each.hpp>
#include <boost/mpl/alias.hpp>
typedef mpl::list<> empty;
typedef mpl::list<float> single;
typedef mpl::push_front<single, int>::type two;
typedef mpl::push_front<empty, int>::type push_on_empty;
BOOST_STATIC_ASSERT(mpl::size<empty>::value == 0); //OK
BOOST_STATIC_ASSERT(mpl::size<single>::value == 1); //OK
BOOST_STATIC_ASSERT(mpl::size<two>::value == 2); //OK
BOOST_STATIC_ASSERT(mpl::size<push_on_empty>::value == 1); //OK
struct type_printer
{
type_printer(std::ostream& s) : f_stream(&s) {}
template< typename U > void operator()(U &)
{
*f_stream << typeid(U).name() << '\n';
}
private:
std::ostream* f_stream;
};
int main() {
mpl::for_each< empty >( type_printer(std::cout) ); //won't compile
mpl::for_each< single >( type_printer(std::cout) ); //OK
mpl::for_each< two >( type_printer(std::cout) ); //OK
mpl::for_each< push_on_empty >( type_printer(std::cout) ); //won't compile
}
Regards,
-Tom Wenisch
Computer Architecture Lab
Carnegie Mellon University
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk