1 /*=============================================================================
2 Copyright (c) 2001-2007 Joel de Guzman
3
4 Distributed under the Boost Software License, Version 1.0. (See accompanying
5 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 ==============================================================================*/
7 #include <iostream>
8 #include <algorithm>
9 #include <vector>
10
11 #include <boost/phoenix/scope.hpp>
12 #include <boost/phoenix/core.hpp>
13 #include <boost/phoenix/operator.hpp>
14 #include <boost/phoenix/function.hpp>
15
16 namespace lazy_stuff
17 {
18 using boost::phoenix::function;
19
20 struct for_each_impl
21 {
22 typedef void result_type;
23
24 template <typename C, typename F>
operator ()lazy_stuff::for_each_impl25 void operator()(C& c, F f) const
26 {
27 std::for_each(c.begin(), c.end(), f);
28 }
29 };
30
31 function<for_each_impl> const for_each = for_each_impl();
32
33 struct push_back_impl
34 {
35 typedef void result_type;
36
37 template <typename C, typename T>
operator ()lazy_stuff::push_back_impl38 void operator()(C& c, T& x) const
39 {
40 c.push_back(x);
41 }
42 };
43
44 function<push_back_impl> const push_back = push_back_impl();
45 }
46
47 int
main()48 main()
49 {
50 {
51 using lazy_stuff::for_each;
52 using lazy_stuff::push_back;
53
54 using boost::phoenix::lambda;
55 using boost::phoenix::arg_names::arg1;
56 using boost::phoenix::arg_names::arg2;
57 using boost::phoenix::local_names::_a;
58
59 int x = 10;
60 std::vector<std::vector<int> > v(10);
61
62 for_each(arg1,
63 lambda(_a = arg2)
64 [
65 push_back(arg1, _a)
66 ]
67 )
68 (v, x);
69 }
70
71 return 0;
72 }
73
74