for_each2.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. namespace
  17. {
  18. void for_each_test()
  19. {
  20. return;
  21. using boost::phoenix::for_each;
  22. using boost::phoenix::lambda;
  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. int x = 0;
  29. for_each(arg1, lambda[ref(x) += arg1])(v);
  30. BOOST_TEST(x == 45);
  31. return;
  32. }
  33. }
  34. int main()
  35. {
  36. for_each_test();
  37. boost::report_errors();
  38. }