lambda_tests19.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /*=============================================================================
  2. Copyright (c) 2001-2007 Joel de Guzman
  3. Copyright (c) 2014 John Fletcher
  4. Copyright (c) 2018 Kohei Takahsahi
  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 <vector>
  9. #include <boost/detail/lightweight_test.hpp>
  10. #include <boost/phoenix/core.hpp>
  11. #include <boost/phoenix/operator/self.hpp>
  12. #include <boost/phoenix/operator/arithmetic.hpp>
  13. #include <boost/phoenix/scope/lambda.hpp>
  14. #include <boost/phoenix/stl/algorithm/iteration.hpp>
  15. #include <boost/phoenix/stl/container.hpp>
  16. int main()
  17. {
  18. using boost::phoenix::lambda;
  19. using boost::phoenix::ref;
  20. using boost::phoenix::arg_names::_1;
  21. using boost::phoenix::arg_names::_2;
  22. using boost::phoenix::local_names::_a;
  23. using boost::phoenix::placeholders::arg1;
  24. using boost::phoenix::for_each;
  25. using boost::phoenix::push_back;
  26. int x = 10;
  27. std::vector<std::vector<int> > v(10);
  28. for_each(_1, lambda(_a = _2)[push_back(_1, _a)])(v, x);
  29. int y = 0;
  30. for_each(arg1, lambda[ref(y) += _1[0]])(v);
  31. BOOST_TEST(y == 100);
  32. return boost::report_errors();
  33. }