]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/phoenix/test/statement/if_tests.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / phoenix / test / statement / if_tests.cpp
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 <vector>
9 #include <algorithm>
10 #include <boost/detail/lightweight_test.hpp>
11 #include <boost/phoenix/core.hpp>
12 #include <boost/phoenix/statement.hpp>
13 #include <boost/phoenix/operator.hpp>
14
15 int
16 main()
17 {
18 using boost::phoenix::arg_names::arg1;
19 using boost::phoenix::if_;
20 using boost::phoenix::ref;
21
22 int init[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
23 std::vector<int> v(init, init+10);
24
25 std::cout << std::dec;
26 int x = 0;
27
28 for_each(v.begin(), v.end(),
29 if_(arg1 > 3 && arg1 <= 8)
30 [
31 std::cout << arg1 << ", ",
32 ref(x) += arg1
33 ]
34 );
35
36 std::cout << std::endl;
37 BOOST_TEST(x == 4+5+6+7+8);
38
39 x = 0;
40 int y = 0;
41 int z = 0;
42
43 for_each(v.begin(), v.end(),
44 if_(arg1 > 5)
45 [
46 std::cout << arg1 << " > 5\n",
47 ref(x) += arg1
48 ]
49 .else_
50 [
51 if_(arg1 == 5)
52 [
53 std::cout << arg1 << " == 5\n",
54 ref(z) += arg1
55 ]
56 .else_
57 [
58 std::cout << arg1 << " < 5\n",
59 ref(y) += arg1
60 ]
61 ]
62 );
63
64 std::cout << std::endl;
65 BOOST_TEST(x == 6+7+8+9+10);
66 BOOST_TEST(y == 1+2+3+4);
67 BOOST_TEST(z == 5);
68
69 return boost::report_errors();
70 }