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 #include <boost/typeof/std/ostream.hpp> 20 21 namespace 22 { 23 for_test()24 void for_test() 25 { 26 using boost::phoenix::for_; 27 using boost::phoenix::val; 28 using boost::phoenix::ref; 29 using boost::phoenix::arg_names::arg1; 30 31 std::vector<int> v; 32 for (int i = 1; i < 10; i++) 33 v.push_back(i); 34 35 std::string test_str("(123456789)"); 36 std::ostringstream out; 37 int iii; 38 int size = v.size(); 39 ( 40 out << val("("), 41 for_(ref(iii) = 0, ref(iii) < size, ++ref(iii) ) 42 [ out << arg1[ref(iii)] ], 43 out << val(")") 44 )(v); 45 BOOST_TEST(out.str() == test_str); 46 return; 47 } 48 49 } 50 main()51int main() 52 { 53 for_test(); 54 boost::report_errors(); 55 } 56