From 58e77e80a5d7f7a45cfb2a8722f398a36672e44d Mon Sep 17 00:00:00 2001 From: Dave Abrahams Date: Thu, 16 Jan 2003 22:41:25 +0000 Subject: [PATCH] Add test for default-identity version [SVN r16918] --- test/for_each.cpp | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) 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);