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/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>
37 template<typename X
, typename Y
>
42 point() : x(0), y(0), z(0) {}
43 point(X x_
, Y y_
, int z_
) : x(x_
), y(y_
), z(z_
) {}
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_
; }
61 #if BOOST_PP_VARIADICS
63 BOOST_FUSION_ADAPT_TPL_ADT(
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
))
71 #else // BOOST_PP_VARIADICS
73 BOOST_FUSION_ADAPT_TPL_ADT(
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
))
82 template <typename TypeToConstruct
>
83 class empty_adt_templated_factory
{
85 TypeToConstruct
operator()() {
86 return TypeToConstruct();
91 BOOST_FUSION_ADAPT_TPL_ADT(
93 (empty_adt_templated_factory
)(TypeToConstruct
),
99 using namespace boost::fusion
;
101 typedef ns::point
<int, int> point
;
102 typedef ns::point
<std::string
, std::string
> name
;
104 std::cout
<< tuple_open('[');
105 std::cout
<< tuple_close(']');
106 std::cout
<< tuple_delimiter(", ");
109 BOOST_MPL_ASSERT_NOT((traits::is_view
<point
>));
110 BOOST_STATIC_ASSERT(!traits::is_view
<point
>::value
);
111 point
p(123, 456, 789);
113 std::cout
<< at_c
<0>(p
) << std::endl
;
114 std::cout
<< at_c
<1>(p
) << std::endl
;
115 std::cout
<< at_c
<2>(p
) << std::endl
;
116 std::cout
<< p
<< std::endl
;
117 BOOST_TEST(p
== make_vector(123, 456, 789));
122 BOOST_TEST(p
== make_vector(6, 9, 12));
124 BOOST_STATIC_ASSERT(boost::fusion::result_of::size
<point
>::value
== 3);
125 BOOST_STATIC_ASSERT(!boost::fusion::result_of::empty
<point
>::value
);
127 BOOST_TEST(front(p
) == 6);
128 BOOST_TEST(back(p
) == 12);
132 boost::fusion::vector
<int, float, int> v1(4, 2.f
, 2);
134 boost::fusion::vector
<long, double, int> v3(5, 4., 4);
136 BOOST_TEST(v1
<= v2
);
138 BOOST_TEST(v2
>= v1
);
140 BOOST_TEST(v2
<= v3
);
142 BOOST_TEST(v3
>= v2
);
146 boost::fusion::vector
<std::string
, std::string
, int> v1("Lincoln", "Abraham", 3);
147 name
v2("Roosevelt", "Franklin", 3);
148 name
v3("Roosevelt", "Theodore", 3);
150 BOOST_TEST(v1
<= v2
);
152 BOOST_TEST(v2
>= v1
);
154 BOOST_TEST(v2
<= v3
);
156 BOOST_TEST(v3
>= v2
);
160 // conversion from point to vector
162 boost::fusion::vector
<int, long, int> v(p
);
167 // conversion from point to list
169 boost::fusion::list
<int, long, int> l(p
);
174 BOOST_MPL_ASSERT((boost::mpl::is_sequence
<point
>));
175 BOOST_MPL_ASSERT((boost::is_same
<
176 boost::fusion::result_of::value_at_c
<point
,0>::type
177 , boost::mpl::front
<point
>::type
>));
180 return boost::report_errors();