]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/fusion/test/sequence/adapt_assoc_adt.cpp
1 /*=============================================================================
2 Copyright (c) 2010 Christopher Schmidt
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.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>
35 point() : x(0), y(0), z(0) {}
36 point(int in_x
, int in_y
, int in_z
) : x(in_x
), y(in_y
), z(in_z
) {}
38 int get_x() const { return x
; }
39 int get_y() const { return y
; }
40 int get_z() const { return z
; }
41 void set_x(int x_
) { x
= x_
; }
42 void set_y(int y_
) { y
= y_
; }
43 void set_z(int z_
) { z
= z_
; }
53 #if BOOST_PP_VARIADICS
55 BOOST_FUSION_ADAPT_ASSOC_ADT(
57 (int, int, obj
.get_x(), obj
.set_x(val
), ns::x_member
)
58 (int, int, obj
.get_y(), obj
.set_y(val
), ns::y_member
)
59 (obj
.get_z(), obj
.set_z(val
), ns::z_member
)
62 #else // BOOST_PP_VARIADICS
64 BOOST_FUSION_ADAPT_ASSOC_ADT(
66 (int, int, obj
.get_x(), obj
.set_x(val
), ns::x_member
)
67 (int, int, obj
.get_y(), obj
.set_y(val
), ns::y_member
)
68 (auto, auto, obj
.get_z(), obj
.set_z(val
), ns::z_member
)
74 BOOST_FUSION_ADAPT_ASSOC_ADT(empty_adt
,)
79 using namespace boost::fusion
;
81 std::cout
<< tuple_open('[');
82 std::cout
<< tuple_close(']');
83 std::cout
<< tuple_delimiter(", ");
86 BOOST_MPL_ASSERT_NOT((traits::is_view
<ns::point
>));
87 BOOST_STATIC_ASSERT(!traits::is_view
<ns::point
>::value
);
88 ns::point
p(123, 456, 789);
90 std::cout
<< at_c
<0>(p
) << std::endl
;
91 std::cout
<< at_c
<1>(p
) << std::endl
;
92 std::cout
<< at_c
<2>(p
) << std::endl
;
93 std::cout
<< p
<< std::endl
;
94 BOOST_TEST(p
== make_vector(123, 456, 789));
99 BOOST_TEST(p
== make_vector(6, 9, 12));
101 BOOST_STATIC_ASSERT(boost::fusion::result_of::size
<ns::point
>::value
== 3);
102 BOOST_STATIC_ASSERT(!boost::fusion::result_of::empty
<ns::point
>::value
);
104 BOOST_TEST(front(p
) == 6);
105 BOOST_TEST(back(p
) == 12);
109 boost::fusion::vector
<int, float, int> v1(4, 2.f
, 2);
110 ns::point
v2(5, 3, 3);
111 boost::fusion::vector
<long, double, int> v3(5, 4., 4);
113 BOOST_TEST(v1
<= v2
);
115 BOOST_TEST(v2
>= v1
);
117 BOOST_TEST(v2
<= v3
);
119 BOOST_TEST(v3
>= v2
);
123 // conversion from ns::point to vector
124 ns::point
p(5, 3, 3);
125 boost::fusion::vector
<int, long, int> v(p
);
130 // conversion from ns::point to list
131 ns::point
p(5, 3, 3);
132 boost::fusion::list
<int, long, int> l(p
);
137 BOOST_MPL_ASSERT((boost::mpl::is_sequence
<ns::point
>));
138 BOOST_MPL_ASSERT((boost::is_same
<
139 boost::fusion::result_of::value_at_c
<ns::point
,0>::type
140 , boost::mpl::front
<ns::point
>::type
>));
145 BOOST_MPL_ASSERT((boost::fusion::result_of::has_key
<ns::point
, ns::x_member
>));
146 BOOST_MPL_ASSERT((boost::fusion::result_of::has_key
<ns::point
, ns::y_member
>));
147 BOOST_MPL_ASSERT((boost::fusion::result_of::has_key
<ns::point
, ns::z_member
>));
148 BOOST_MPL_ASSERT((boost::mpl::not_
<boost::fusion::result_of::has_key
<ns::point
, ns::non_member
> >));
151 BOOST_MPL_ASSERT((boost::is_same
<boost::fusion::result_of::value_at_key
<ns::point
, ns::x_member
>::type
, int>));
152 BOOST_MPL_ASSERT((boost::is_same
<boost::fusion::result_of::value_at_key
<ns::point
, ns::y_member
>::type
, int>));
153 BOOST_MPL_ASSERT((boost::is_same
<boost::fusion::result_of::value_at_key
<ns::point
, ns::z_member
>::type
, int>));
155 ns::point
p(5, 3, 1);
157 BOOST_TEST(at_key
<ns::x_member
>(p
) == 5);
158 BOOST_TEST(at_key
<ns::y_member
>(p
) == 3);
159 BOOST_TEST(at_key
<ns::z_member
>(p
) == 1);
162 return boost::report_errors();