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>
31 template<typename X
, typename Y
, typename Z
>
36 point() : x(0), y(0), z(0) {}
37 point(X in_x
, Y in_y
, Z in_z
) : x(in_x
), y(in_y
), z(in_z
) {}
39 X
get_x() const { return x
; }
40 Y
get_y() const { return y
; }
41 Z
get_z() const { return z
; }
42 void set_x(X x_
) { x
= x_
; }
43 void set_y(Y y_
) { y
= y_
; }
44 void set_z(Z z_
) { z
= z_
; }
54 #if BOOST_PP_VARIADICS
55 BOOST_FUSION_ADAPT_ASSOC_TPL_ADT(
58 (X
, X
, obj
.get_x(), obj
.set_x(val
), ns::x_member
)
59 (Y
, Y
, obj
.get_y(), obj
.set_y(val
), ns::y_member
)
60 (obj
.get_z(), obj
.set_z(val
), ns::z_member
)
63 #else // BOOST_PP_VARIADICS
64 BOOST_FUSION_ADAPT_ASSOC_TPL_ADT(
67 (X
, X
, obj
.get_x(), obj
.set_x(val
), ns::x_member
)
68 (Y
, Y
, obj
.get_y(), obj
.set_y(val
), ns::y_member
)
69 (auto, auto, obj
.get_z(), obj
.set_z(val
), ns::z_member
)
74 template <typename TypeToConstruct
>
75 class empty_adt_templated_factory
{
77 TypeToConstruct
operator()() {
78 return TypeToConstruct();
83 BOOST_FUSION_ADAPT_ASSOC_TPL_ADT(
85 (empty_adt_templated_factory
)(TypeToConstruct
),
91 using namespace boost::fusion
;
93 typedef ns::point
<int,int,long> point
;
95 std::cout
<< tuple_open('[');
96 std::cout
<< tuple_close(']');
97 std::cout
<< tuple_delimiter(", ");
100 BOOST_MPL_ASSERT_NOT((traits::is_view
<point
>));
101 point
p(123, 456, 789);
103 std::cout
<< at_c
<0>(p
) << std::endl
;
104 std::cout
<< at_c
<1>(p
) << std::endl
;
105 std::cout
<< at_c
<2>(p
) << std::endl
;
106 std::cout
<< p
<< std::endl
;
107 BOOST_TEST(p
== make_vector(123, 456, 789));
112 BOOST_TEST(p
== make_vector(6, 9, 12));
114 BOOST_STATIC_ASSERT(boost::fusion::result_of::size
<point
>::value
== 3);
115 BOOST_STATIC_ASSERT(!boost::fusion::result_of::empty
<point
>::value
);
117 BOOST_TEST(front(p
) == 6);
118 BOOST_TEST(back(p
) == 12);
122 boost::fusion::vector
<int, float, long> v1(4, 2.f
, 2);
124 boost::fusion::vector
<long, double, long> v3(5, 4., 4);
126 BOOST_TEST(v1
<= v2
);
128 BOOST_TEST(v2
>= v1
);
130 BOOST_TEST(v2
<= v3
);
132 BOOST_TEST(v3
>= v2
);
136 // conversion from point to vector
138 boost::fusion::vector
<int, long, int> v(p
);
143 // conversion from point to list
145 boost::fusion::list
<int, long, int> l(p
);
150 BOOST_MPL_ASSERT((boost::mpl::is_sequence
<point
>));
151 BOOST_MPL_ASSERT((boost::is_same
<
152 boost::fusion::result_of::value_at_c
<point
,0>::type
153 , boost::mpl::front
<point
>::type
>));
158 BOOST_MPL_ASSERT((boost::fusion::result_of::has_key
<point
, ns::x_member
>));
159 BOOST_MPL_ASSERT((boost::fusion::result_of::has_key
<point
, ns::y_member
>));
160 BOOST_MPL_ASSERT((boost::fusion::result_of::has_key
<point
, ns::z_member
>));
161 BOOST_MPL_ASSERT((boost::mpl::not_
<boost::fusion::result_of::has_key
<point
, ns::non_member
> >));
163 BOOST_MPL_ASSERT((boost::is_same
<boost::fusion::result_of::value_at_key
<point
, ns::x_member
>::type
, int>));
164 BOOST_MPL_ASSERT((boost::is_same
<boost::fusion::result_of::value_at_key
<point
, ns::y_member
>::type
, int>));
165 BOOST_MPL_ASSERT((boost::is_same
<boost::fusion::result_of::value_at_key
<point
, ns::z_member
>::type
, long>));
169 BOOST_TEST(at_key
<ns::x_member
>(p
) == 5);
170 BOOST_TEST(at_key
<ns::y_member
>(p
) == 3);
171 BOOST_TEST(at_key
<ns::z_member
>(p
) == 1);
174 return boost::report_errors();