]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/fusion/test/sequence/adapt_assoc_adt_named.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / fusion / test / sequence / adapt_assoc_adt_named.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/sequence.hpp>
9 #include <boost/fusion/support.hpp>
10 #include <boost/fusion/container/list.hpp>
11 #include <boost/fusion/container/vector.hpp>
12 #include <boost/fusion/container/generation/make_vector.hpp>
13 #include <boost/fusion/adapted/adt/adapt_assoc_adt_named.hpp>
14 #include <boost/mpl/assert.hpp>
15 #include <boost/mpl/not.hpp>
16 #include <boost/mpl/front.hpp>
17 #include <boost/mpl/is_sequence.hpp>
18 #include <boost/type_traits/is_same.hpp>
19 #include <boost/static_assert.hpp>
20 #include <iostream>
21 #include <string>
22
23 namespace ns
24 {
25 struct x_member;
26 struct y_member;
27 struct z_member;
28
29 class point
30 {
31 public:
32
33 point() : x(0), y(0) {}
34 point(int in_x, int in_y) : x(in_x), y(in_y) {}
35
36 int get_x() const { return x; }
37 int get_y() const { return y; }
38 void set_x(int x_) { x = x_; }
39 void set_y(int y_) { y = y_; }
40
41 private:
42
43 int x;
44 int y;
45 };
46 }
47
48 #if BOOST_PP_VARIADICS
49
50 BOOST_FUSION_ADAPT_ASSOC_ADT_NAMED(
51 ns::point,
52 point,
53 (obj.get_x(), obj.set_x(val), ns::x_member)
54 (int, int, obj.get_y(), obj.set_y(val), ns::y_member)
55 )
56
57 #else // BOOST_PP_VARIADICS
58
59 BOOST_FUSION_ADAPT_ASSOC_ADT_NAMED(
60 ns::point,
61 point,
62 (auto, auto, obj.get_x(), obj.set_x(val), ns::x_member)
63 (int, int, obj.get_y(), obj.set_y(val), ns::y_member)
64 )
65
66 #endif
67
68
69 class empty_adt{};
70 BOOST_FUSION_ADAPT_ASSOC_ADT_NAMED(empty_adt, renamed_empty_adt,)
71
72 int
73 main()
74 {
75 using namespace boost::fusion;
76
77 std::cout << tuple_open('[');
78 std::cout << tuple_close(']');
79 std::cout << tuple_delimiter(", ");
80
81 {
82 BOOST_MPL_ASSERT((traits::is_view<adapted::point>));
83 ns::point basep(123, 456);
84 adapted::point p(basep);
85
86 std::cout << at_c<0>(p) << std::endl;
87 std::cout << at_c<1>(p) << std::endl;
88 std::cout << p << std::endl;
89 BOOST_TEST(p == make_vector(123, 456));
90
91 at_c<0>(p) = 6;
92 at_c<1>(p) = 9;
93 BOOST_TEST(p == make_vector(6, 9));
94
95 BOOST_STATIC_ASSERT(boost::fusion::result_of::size<adapted::point>::value == 2);
96 BOOST_STATIC_ASSERT(!boost::fusion::result_of::empty<adapted::point>::value);
97
98 BOOST_TEST(front(p) == 6);
99 BOOST_TEST(back(p) == 9);
100 }
101
102 {
103 boost::fusion::vector<int, float> v1(4, 2.f);
104 ns::point basev2(5, 3);
105 adapted::point v2(basev2);
106 boost::fusion::vector<long, double> v3(5, 4.);
107 BOOST_TEST(v1 < v2);
108 BOOST_TEST(v1 <= v2);
109 BOOST_TEST(v2 > v1);
110 BOOST_TEST(v2 >= v1);
111 BOOST_TEST(v2 < v3);
112 BOOST_TEST(v2 <= v3);
113 BOOST_TEST(v3 > v2);
114 BOOST_TEST(v3 >= v2);
115 }
116
117 {
118 // conversion from adapted::point to vector
119 ns::point basep(5, 3);
120 adapted::point p(basep);
121 boost::fusion::vector<int, long> v(p);
122 v = p;
123 }
124
125 {
126 // conversion from adated::point to list
127 ns::point basep(5, 3);
128 adapted::point p(basep);
129 boost::fusion::list<int, long> l(p);
130 l = p;
131 }
132
133 {
134 BOOST_MPL_ASSERT((boost::mpl::is_sequence<adapted::point>));
135 BOOST_MPL_ASSERT((boost::is_same<
136 boost::fusion::result_of::value_at_c<adapted::point,0>::type
137 , boost::mpl::front<adapted::point>::type>));
138 }
139
140 {
141 // assoc stuff
142 BOOST_MPL_ASSERT((boost::fusion::result_of::has_key<adapted::point, ns::x_member>));
143 BOOST_MPL_ASSERT((boost::fusion::result_of::has_key<adapted::point, ns::y_member>));
144 BOOST_MPL_ASSERT((boost::mpl::not_<boost::fusion::result_of::has_key<adapted::point, ns::z_member> >));
145
146 BOOST_MPL_ASSERT((boost::is_same<boost::fusion::result_of::value_at_key<adapted::point, ns::x_member>::type, int>));
147 BOOST_MPL_ASSERT((boost::is_same<boost::fusion::result_of::value_at_key<adapted::point, ns::y_member>::type, int>));
148
149 ns::point basep(5, 3);
150 adapted::point p(basep);
151
152 BOOST_TEST(at_key<ns::x_member>(p) == 5);
153 BOOST_TEST(at_key<ns::y_member>(p) == 3);
154 }
155
156 return boost::report_errors();
157 }
158