for_test2.cpp 1.3 KB

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