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_struct.hpp>
14 #include <boost/preprocessor/empty.hpp>
15 #include <boost/mpl/assert.hpp>
16 #include <boost/static_assert.hpp>
17 #include <iostream>
18 #include <string>
19
20 BOOST_FUSION_DEFINE_STRUCT(
21 (ns),
22 point,
23 (int, x)
24 (int, y)
25 )
26
27 // Tutorial (compile test only)
28 BOOST_FUSION_DEFINE_STRUCT(
29 (demo), employee,
30 (std::string, name)
31 (int, age)
32 )
33
BOOST_PP_EMPTY()34 BOOST_FUSION_DEFINE_STRUCT(BOOST_PP_EMPTY(), s, (int, m))
35
36 BOOST_FUSION_DEFINE_STRUCT(BOOST_PP_EMPTY(), empty_struct, )
37
38 // Testing non-constexpr compatible types
39 BOOST_FUSION_DEFINE_STRUCT(
40 (ns),
41 employee,
42 (std::string, name)
43 (std::string, nickname)
44 )
45
46 int
47 main()
48 {
49 using namespace boost::fusion;
50
51 std::cout << tuple_open('[');
52 std::cout << tuple_close(']');
53 std::cout << tuple_delimiter(", ");
54
55 {
56 BOOST_MPL_ASSERT_NOT((traits::is_view<ns::point>));
57 BOOST_STATIC_ASSERT(!traits::is_view<ns::point>::value);
58 ns::point p(123, 456);
59
60 std::cout << at_c<0>(p) << std::endl;
61 std::cout << at_c<1>(p) << std::endl;
62 std::cout << p << std::endl;
63 BOOST_TEST(p == make_vector(123, 456));
64
65 at_c<0>(p) = 6;
66 at_c<1>(p) = 9;
67 BOOST_TEST(p == make_vector(6, 9));
68
69 BOOST_STATIC_ASSERT(boost::fusion::result_of::size<ns::point>::value == 2);
70 BOOST_STATIC_ASSERT(!boost::fusion::result_of::empty<ns::point>::value);
71
72 BOOST_TEST(front(p) == 6);
73 BOOST_TEST(back(p) == 9);
74 }
75
76 {
77 vector<int, float> v1(4, 2.f);
78 ns::point v2(5, 3);
79 vector<long, double> v3(5, 4.0);
80 BOOST_TEST(v1 < v2);
81 BOOST_TEST(v1 <= v2);
82 BOOST_TEST(v2 > v1);
83 BOOST_TEST(v2 >= v1);
84 BOOST_TEST(v2 < v3);
85 BOOST_TEST(v2 <= v3);
86 BOOST_TEST(v3 > v2);
87 BOOST_TEST(v3 >= v2);
88 }
89
90 {
91 // conversion from ns::point to vector
92 ns::point p(5, 3);
93 vector<int, long> v(p);
94 v = p;
95 }
96
97 {
98 // conversion from ns::point to list
99 ns::point p(5, 3);
100 list<int, long> l(p);
101 l = p;
102 }
103
104 { // begin/end
105 using namespace boost::fusion;
106
107 typedef boost::fusion::result_of::begin<s>::type b;
108 typedef boost::fusion::result_of::end<s>::type e;
109 // this fails
110 BOOST_MPL_ASSERT((boost::is_same<boost::fusion::result_of::next<b>::type, e>));
111 }
112
113 {
114 ns::point p = make_list(5,3);
115 BOOST_TEST(p == make_vector(5,3));
116
117 p = make_list(3,5);
118 BOOST_TEST(p == make_vector(3,5));
119 }
120
121 {
122 ns::employee emp = make_list("John Doe", "jdoe");
123 std::cout << at_c<0>(emp) << std::endl;
124 std::cout << at_c<1>(emp) << std::endl;
125
126 BOOST_TEST(emp == make_vector("John Doe", "jdoe"));
127 }
128
129 return boost::report_errors();
130 }
131