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