generator2.cpp 989 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. /*=============================================================================
  2. Copyright (c) 2011 Thomas Heller
  3. Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. ==============================================================================*/
  6. #include <boost/phoenix.hpp>
  7. #include <boost/typeof/typeof.hpp>
  8. #include <iostream>
  9. #include <vector>
  10. #include <algorithm>
  11. int main()
  12. {
  13. using boost::phoenix::lambda;
  14. using boost::phoenix::let;
  15. using boost::phoenix::ref;
  16. using boost::phoenix::construct;
  17. using boost::phoenix::local_names::_a;
  18. using boost::phoenix::arg_names::_1;
  19. BOOST_AUTO(
  20. generator
  21. , (lambda
  22. (
  23. _a = val(_1)
  24. )
  25. [
  26. std::cout << _a << " "
  27. , _a++
  28. ] )
  29. );
  30. int i = 0;
  31. std::vector<int> v(10);
  32. std::for_each(v.begin(), v.end(), generator(0));
  33. }