]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/phoenix/test/statement/switch_tests.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / phoenix / test / statement / switch_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
8 #include <iostream>
9 #include <vector>
10 #include <algorithm>
11 #include <boost/detail/lightweight_test.hpp>
12 #include <boost/phoenix/core.hpp>
13 #include <boost/phoenix/statement.hpp>
14 #include <boost/phoenix/operator.hpp>
15
16 int
17 main()
18 {
19 using boost::phoenix::arg_names::_1;
20 using boost::phoenix::case_;
21 using boost::phoenix::switch_;
22 using boost::phoenix::ref;
23 using boost::phoenix::val;
24
25 using std::cout;
26 using std::endl;
27 using std::vector;
28 using std::for_each;
29
30 int init[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
31 vector<int> v(init, init+10);
32
33 for_each(v.begin(), v.end(),
34 switch_(_1)
35 [
36 // wierd case, why not just use if(...), but valid, nonetheless
37 case_<4>(cout << val("<4>") << endl)
38 ]
39 );
40
41 cout << endl;
42 for_each(v.begin(), v.end(),
43 switch_(_1)
44 [
45 // wierd case, but valid, nonetheless
46 default_(cout << val("<any...>") << endl)
47 ]
48 );
49
50 cout << endl;
51
52 for_each(v.begin(), v.end(),
53 switch_(_1)
54 [
55 case_<1>(cout << val("<1>") << endl),
56 case_<2>(cout << val("<2>") << endl),
57 case_<3>(cout << val("<3>") << endl),
58 case_<4>(cout << val("<4>") << endl)
59 ]
60 );
61
62 cout << endl;
63
64 for_each(v.begin(), v.end(),
65 switch_(_1)
66 [
67 case_<1>(cout << val("<1>") << endl),
68 case_<2>(cout << val("<2>") << endl),
69 case_<3>(cout << val("<3>") << endl),
70 case_<4>(cout << val("<4>") << endl),
71 default_(cout << val("<over 4>") << endl)
72 ]
73 );
74
75 return boost::report_errors();
76 }