diff --git a/test/for_each.cpp b/test/for_each.cpp index af53c53..89c710a 100644 --- a/test/for_each.cpp +++ b/test/for_each.cpp @@ -30,9 +30,9 @@ namespace mpl = boost::mpl; using mpl::_; -struct printer +struct type_printer { - printer(std::ostream& s) : f_stream(&s) {} + type_printer(std::ostream& s) : f_stream(&s) {} template< typename U > void operator()(mpl::identity) { *f_stream << typeid(U).name() << '\n'; @@ -42,6 +42,18 @@ struct printer std::ostream* f_stream; }; +struct value_printer +{ + value_printer(std::ostream& s) : f_stream(&s) {} + template< typename U > void operator()(U x) + { + *f_stream << x << '\n'; + } + + private: + std::ostream* f_stream; +}; + #ifdef __ICL # pragma warning(disable:985) #endif @@ -49,7 +61,7 @@ struct printer int main() { typedef mpl::list types; - mpl::for_each< types,mpl::make_identity<_> >(printer(std::cout)); + mpl::for_each< types,mpl::make_identity<_> >(type_printer(std::cout)); typedef mpl::range_c numbers; std::vector v; @@ -65,6 +77,8 @@ int main() ); #endif + mpl::for_each< numbers >(value_printer(std::cout)); + for (int i = 0; i < v.size(); ++i) assert(v[i] == i);