1/*=============================================================================
2 Copyright (c) 2005-2007 Dan Marsden
3 Copyright (c) 2005-2007 Joel de Guzman
4
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
9#include <boost/phoenix/core.hpp>
10#include <boost/phoenix/stl/algorithm/iteration.hpp>
11#include <boost/detail/lightweight_test.hpp>
12
13#include <functional>
14
15namespace
16{
17 struct for_each_tester
18 {
19 int value_;
20 for_each_tester() : value_(0) { }
21 void operator()(
22 int& i)
23 {
24 value_ += i++;
25 return;
26 }
27 };
28
29 void for_each_test()
30 {
31 using boost::phoenix::for_each;
32 using boost::phoenix::arg_names::arg1;
33 int array[] = {1,2,3};
34 BOOST_TEST(for_each(arg1, for_each_tester())(array).value_ == 6);
35 BOOST_TEST(array[0] == 2);
36 BOOST_TEST(array[1] == 3);
37 BOOST_TEST(array[2] == 4);
38 return;
39 }
40
41 void accumulate_test()
42 {
43 using boost::phoenix::accumulate;
44 using boost::phoenix::arg_names::arg1;
45 int array[] = {1,2,3};
46 BOOST_TEST(accumulate(arg1, 0)(array) == 6);
47 BOOST_TEST(boost::phoenix::accumulate(arg1, 0, std::minus<int>())(array) == -6);
48 return;
49 }
50}
51
52int main()
53{
54 for_each_test();
55 accumulate_test();
56 boost::report_errors();
57}
58

source code of boost/libs/phoenix/test/algorithm/iteration.cpp