• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //  bll_and_function.cpp  - The Boost Lambda Library -----------------------
2 //
3 // Copyright (C) 2000-2003 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi)
4 // Copyright (C) 2000-2003 Gary Powell (powellg@amazon.com)
5 //
6 // Distributed under the Boost Software License, Version 1.0. (See
7 // accompanying file LICENSE_1_0.txt or copy at
8 // http://www.boost.org/LICENSE_1_0.txt)
9 //
10 // For more information, see www.boost.org
11 
12 // test using BLL and boost::function
13 
14 #include <boost/core/lightweight_test.hpp>
15 
16 /*
17 #include "boost/lambda/lambda.hpp"
18 #include "boost/lambda/bind.hpp"
19 #include "boost/lambda/algorithm.hpp"
20 */
21 #include <boost/phoenix/core.hpp>
22 #include <boost/phoenix/operator.hpp>
23 #include <boost/phoenix/bind.hpp>
24 #include <boost/phoenix/scope.hpp>
25 #include <boost/phoenix/stl/algorithm/iteration.hpp>
26 
27 #include <vector>
28 #include <map>
29 #include <set>
30 #include <string>
31 
32 #include <iostream>
33 
34 namespace phoenix = boost::phoenix;
35 
test_foreach()36 void test_foreach() {
37 
38     using phoenix::placeholders::_1;
39     using phoenix::ref;
40     using phoenix::lambda;
41 
42   int a[10][20];
43   int sum = 0;
44 
45   //for_each(arg1, for_each_tester())(array).value_;
46 
47   // Was:
48   // std::for_each(a, a + 10,
49   //               bind(ll::for_each(), _1, _1 + 20,
50   //                    protect((_1 = var(sum), ++var(sum)))));
51   // var replaced with ref, protect(..) replaced with lambda[..], no need for bind
52   // phoenix algorithms are range based
53   std::for_each(a, a + 10,
54           phoenix::for_each(_1, lambda[_1 = ref(sum), ++ref(sum)]));
55                 /*phoenix::bind(phoenix::for_each, _1,
56                             lambda[_1 = ref(sum), ++ref(sum)]));*/
57 
58   sum = 0;
59   // Was:
60   // std::for_each(a, a + 10,
61   //               bind(ll::for_each(), _1, _1 + 20,
62   //                 protect((sum += _1))));
63   //
64   std::for_each(a, a + 10,
65                 phoenix::for_each( _1,
66                      lambda[(ref(sum) += _1)]));
67 
68   BOOST_TEST_EQ(sum, (199 + 1)/ 2 * 199);
69 }
70 
71 // More tests needed (for all algorithms)
72 
main()73 int main()
74 {
75   test_foreach();
76 
77   return boost::report_errors();
78 }
79