]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/fusion/test/sequence/adapt_tpl_adt.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / fusion / test / sequence / adapt_tpl_adt.cpp
1 /*=============================================================================
2 Copyright (c) 2010 Christopher Schmidt
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 <boost/detail/lightweight_test.hpp>
8 #include <boost/fusion/adapted/adt/adapt_adt.hpp>
9 #include <boost/fusion/sequence/intrinsic/at.hpp>
10 #include <boost/fusion/sequence/intrinsic/size.hpp>
11 #include <boost/fusion/sequence/intrinsic/empty.hpp>
12 #include <boost/fusion/sequence/intrinsic/front.hpp>
13 #include <boost/fusion/sequence/intrinsic/back.hpp>
14 #include <boost/fusion/sequence/intrinsic/value_at.hpp>
15 #include <boost/fusion/sequence/io/out.hpp>
16 #include <boost/fusion/container/vector/vector.hpp>
17 #include <boost/fusion/container/list/list.hpp>
18 #include <boost/fusion/container/generation/make_vector.hpp>
19 #include <boost/fusion/container/vector/convert.hpp>
20 #include <boost/fusion/sequence/comparison/equal_to.hpp>
21 #include <boost/fusion/sequence/comparison/not_equal_to.hpp>
22 #include <boost/fusion/sequence/comparison/less.hpp>
23 #include <boost/fusion/sequence/comparison/less_equal.hpp>
24 #include <boost/fusion/sequence/comparison/greater.hpp>
25 #include <boost/fusion/sequence/comparison/greater_equal.hpp>
26 #include <boost/fusion/mpl.hpp>
27 #include <boost/fusion/support/is_view.hpp>
28 #include <boost/mpl/front.hpp>
29 #include <boost/mpl/is_sequence.hpp>
30 #include <boost/mpl/assert.hpp>
31 #include <boost/static_assert.hpp>
32 #include <iostream>
33 #include <string>
34
35 namespace ns
36 {
37 template<typename X, typename Y>
38 class point
39 {
40 public:
41
42 point() : x(0), y(0), z(0) {}
43 point(X x_, Y y_, int z_) : x(x_), y(y_), z(z_) {}
44
45 X get_x() const { return x; }
46 Y get_y() const { return y; }
47 int get_z() const { return z; }
48 void set_x(X x_) { x = x_; }
49 void set_y(Y y_) { y = y_; }
50 void set_z(int z_) { z = z_; }
51
52 private:
53
54 X x;
55 Y y;
56 int z;
57 };
58 }
59
60
61 #if BOOST_PP_VARIADICS
62
63 BOOST_FUSION_ADAPT_TPL_ADT(
64 (X)(Y),
65 (ns::point)(X)(Y),
66 (X, X, obj.get_x(), obj.set_x(val))
67 (Y, Y, obj.get_y(), obj.set_y(val))
68 (obj.get_z(), obj.set_z(val))
69 )
70
71 #else // BOOST_PP_VARIADICS
72
73 BOOST_FUSION_ADAPT_TPL_ADT(
74 (X)(Y),
75 (ns::point)(X)(Y),
76 (X, X, obj.get_x(), obj.set_x(val))
77 (Y, Y, obj.get_y(), obj.set_y(val))
78 (auto, auto, obj.get_z(), obj.set_z(val))
79 )
80 #endif
81
82 template <typename TypeToConstruct>
83 class empty_adt_templated_factory {
84
85 TypeToConstruct operator()() {
86 return TypeToConstruct();
87 }
88
89 };
90
91 BOOST_FUSION_ADAPT_TPL_ADT(
92 (TypeToConstruct),
93 (empty_adt_templated_factory)(TypeToConstruct),
94 )
95
96 int
97 main()
98 {
99 using namespace boost::fusion;
100
101 typedef ns::point<int, int> point;
102 typedef ns::point<std::string, std::string> name;
103
104 std::cout << tuple_open('[');
105 std::cout << tuple_close(']');
106 std::cout << tuple_delimiter(", ");
107
108 {
109 BOOST_MPL_ASSERT_NOT((traits::is_view<point>));
110 point p(123, 456, 789);
111
112 std::cout << at_c<0>(p) << std::endl;
113 std::cout << at_c<1>(p) << std::endl;
114 std::cout << at_c<2>(p) << std::endl;
115 std::cout << p << std::endl;
116 BOOST_TEST(p == make_vector(123, 456, 789));
117
118 at_c<0>(p) = 6;
119 at_c<1>(p) = 9;
120 at_c<2>(p) = 12;
121 BOOST_TEST(p == make_vector(6, 9, 12));
122
123 BOOST_STATIC_ASSERT(boost::fusion::result_of::size<point>::value == 3);
124 BOOST_STATIC_ASSERT(!boost::fusion::result_of::empty<point>::value);
125
126 BOOST_TEST(front(p) == 6);
127 BOOST_TEST(back(p) == 12);
128 }
129
130 {
131 boost::fusion::vector<int, float, int> v1(4, 2.f, 2);
132 point v2(5, 3, 3);
133 boost::fusion::vector<long, double, int> v3(5, 4., 4);
134 BOOST_TEST(v1 < v2);
135 BOOST_TEST(v1 <= v2);
136 BOOST_TEST(v2 > v1);
137 BOOST_TEST(v2 >= v1);
138 BOOST_TEST(v2 < v3);
139 BOOST_TEST(v2 <= v3);
140 BOOST_TEST(v3 > v2);
141 BOOST_TEST(v3 >= v2);
142 }
143
144 {
145 boost::fusion::vector<std::string, std::string, int> v1("Lincoln", "Abraham", 3);
146 name v2("Roosevelt", "Franklin", 3);
147 name v3("Roosevelt", "Theodore", 3);
148 BOOST_TEST(v1 < v2);
149 BOOST_TEST(v1 <= v2);
150 BOOST_TEST(v2 > v1);
151 BOOST_TEST(v2 >= v1);
152 BOOST_TEST(v2 < v3);
153 BOOST_TEST(v2 <= v3);
154 BOOST_TEST(v3 > v2);
155 BOOST_TEST(v3 >= v2);
156 }
157
158 {
159 // conversion from point to vector
160 point p(5, 3, 3);
161 boost::fusion::vector<int, long, int> v(p);
162 v = p;
163 }
164
165 {
166 // conversion from point to list
167 point p(5, 3, 3);
168 boost::fusion::list<int, long, int> l(p);
169 l = p;
170 }
171
172 {
173 BOOST_MPL_ASSERT((boost::mpl::is_sequence<point>));
174 BOOST_MPL_ASSERT((boost::is_same<
175 boost::fusion::result_of::value_at_c<point,0>::type
176 , boost::mpl::front<point>::type>));
177 }
178
179 return boost::report_errors();
180 }
181