1 /*============================================================================= 2 Copyright (c) 2005-2007 Dan Marsden 3 Copyright (c) 2005-2007 Joel de Guzman 4 Copyright (c) 2014 John Fletcher 5 6 Distributed under the Boost Software License, Version 1.0. (See accompanying 7 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 8 ==============================================================================*/ 9 10 #include <boost/phoenix.hpp> 11 #include <boost/phoenix/core.hpp> 12 #include <boost/phoenix/stl/algorithm/iteration.hpp> 13 #include <boost/detail/lightweight_test.hpp> 14 15 #include <functional> 16 #include <vector> 17 #include <string> 18 #include <sstream> 19 20 namespace 21 { 22 for_each_test()23 void for_each_test() 24 { 25 using boost::phoenix::for_each; 26 using boost::phoenix::lambda; 27 using boost::phoenix::val; 28 using boost::phoenix::arg_names::arg1; 29 30 std::vector<int> v; 31 for (int i = 1; i < 10; i++) 32 v.push_back(i); 33 34 std::string test_str("(123456789)"); 35 std::ostringstream out; 36 ( 37 out << val("("), 38 for_each(arg1, lambda[out << arg1]), 39 out << val(")") 40 )(v); 41 BOOST_TEST(out.str() == test_str); 42 return; 43 } 44 45 } 46 main()47int main() 48 { 49 for_each_test(); 50 boost::report_errors(); 51 } 52