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
8 #include <boost/detail/lightweight_test.hpp>
9 #include <boost/fusion/sequence.hpp>
10 #include <boost/fusion/container.hpp>
11 #include <boost/fusion/support.hpp>
12 #include <boost/fusion/adapted/struct/define_assoc_struct.hpp>
13 #include <boost/preprocessor/empty.hpp>
14 #include <boost/mpl/assert.hpp>
15 #include <boost/static_assert.hpp>
16 #include <iostream>
17
18 namespace ns
19 {
20 struct x_member;
21 struct y_member;
22 struct z_member;
23 }
24
25 BOOST_FUSION_DEFINE_ASSOC_STRUCT(
26 (ns),
27 point,
28 (int, x, ns::x_member)
29 (int, y, ns::y_member)
30 )
31
BOOST_PP_EMPTY()32 BOOST_FUSION_DEFINE_ASSOC_STRUCT(BOOST_PP_EMPTY(), empty_struct, )
33
34 int
35 main()
36 {
37 using namespace boost::fusion;
38
39 std::cout << tuple_open('[');
40 std::cout << tuple_close(']');
41 std::cout << tuple_delimiter(", ");
42
43 {
44 BOOST_MPL_ASSERT_NOT((traits::is_view<ns::point>));
45 BOOST_STATIC_ASSERT(!traits::is_view<ns::point>::value);
46 ns::point p(123, 456);
47
48 std::cout << at_c<0>(p) << std::endl;
49 std::cout << at_c<1>(p) << std::endl;
50 std::cout << p << std::endl;
51 BOOST_TEST(p == make_vector(123, 456));
52
53 at_c<0>(p) = 6;
54 at_c<1>(p) = 9;
55 BOOST_TEST(p == make_vector(6, 9));
56
57 BOOST_STATIC_ASSERT(boost::fusion::result_of::size<ns::point>::value == 2);
58 BOOST_STATIC_ASSERT(!boost::fusion::result_of::empty<ns::point>::value);
59
60 BOOST_TEST(front(p) == 6);
61 BOOST_TEST(back(p) == 9);
62 }
63
64 {
65 vector<int, float> v1(4, 2.f);
66 ns::point v2(5, 3);
67 vector<long, double> v3(5, 4.);
68 BOOST_TEST(v1 < v2);
69 BOOST_TEST(v1 <= v2);
70 BOOST_TEST(v2 > v1);
71 BOOST_TEST(v2 >= v1);
72 BOOST_TEST(v2 < v3);
73 BOOST_TEST(v2 <= v3);
74 BOOST_TEST(v3 > v2);
75 BOOST_TEST(v3 >= v2);
76 }
77
78 {
79 // conversion from ns::point to vector
80 ns::point p(5, 3);
81 vector<int, long> v(p);
82 v = p;
83 }
84
85 {
86 // conversion from ns::point to list
87 ns::point p(5, 3);
88 list<int, long> l(p);
89 l = p;
90 }
91
92 {
93 // assoc stuff
94 BOOST_MPL_ASSERT((boost::fusion::result_of::has_key<ns::point, ns::x_member>));
95 BOOST_MPL_ASSERT((boost::fusion::result_of::has_key<ns::point, ns::y_member>));
96 BOOST_MPL_ASSERT((boost::mpl::not_<boost::fusion::result_of::has_key<ns::point, ns::z_member> >));
97
98 BOOST_MPL_ASSERT((boost::is_same<boost::fusion::result_of::value_at_key<ns::point, ns::x_member>::type, int>));
99 BOOST_MPL_ASSERT((boost::is_same<boost::fusion::result_of::value_at_key<ns::point, ns::y_member>::type, int>));
100
101 ns::point p(5, 3);
102
103 BOOST_TEST(at_key<ns::x_member>(p) == 5);
104 BOOST_TEST(at_key<ns::y_member>(p) == 3);
105 }
106
107 {
108 ns::point p = make_list(5,3);
109 BOOST_TEST(p == make_vector(5,3));
110
111 p = make_list(3,5);
112 BOOST_TEST(p == make_vector(3,5));
113 }
114
115 return boost::report_errors();
116 }
117
118