]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | /*============================================================================= |
2 | Copyright (c) 2010, 2012 Christopher Schmidt, nathan Ridge | |
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_inline.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 | struct cls | |
21 | { | |
22 | BOOST_FUSION_DEFINE_TPL_STRUCT_INLINE( | |
23 | (X)(Y), | |
24 | point, | |
25 | (X, x) | |
26 | (Y, y) | |
27 | ) | |
28 | }; | |
29 | ||
30 | template <typename = int> | |
31 | struct tpl_cls | |
32 | { | |
33 | BOOST_FUSION_DEFINE_TPL_STRUCT_INLINE( | |
34 | (X)(Y), | |
35 | point, | |
36 | (X, x) | |
37 | (Y, y) | |
38 | ) | |
39 | }; | |
40 | ||
41 | namespace ns | |
42 | { | |
43 | BOOST_FUSION_DEFINE_TPL_STRUCT_INLINE((M), s, (M, m)) | |
44 | ||
45 | BOOST_FUSION_DEFINE_TPL_STRUCT_INLINE((M), empty_struct, ) | |
46 | } | |
47 | ||
48 | template <typename Point> | |
49 | void run_test() | |
50 | { | |
51 | using namespace boost::fusion; | |
52 | ||
53 | std::cout << tuple_open('['); | |
54 | std::cout << tuple_close(']'); | |
55 | std::cout << tuple_delimiter(", "); | |
56 | ||
57 | { | |
58 | BOOST_STATIC_ASSERT(boost::fusion::result_of::size<ns::empty_struct<int> >::value == 0); | |
59 | BOOST_STATIC_ASSERT(boost::fusion::result_of::empty<ns::empty_struct<int> >::value); | |
60 | } | |
61 | ||
62 | { | |
63 | BOOST_MPL_ASSERT_NOT((traits::is_view<Point>)); | |
64 | Point p(123, 456); | |
65 | ||
66 | std::cout << at_c<0>(p) << std::endl; | |
67 | std::cout << at_c<1>(p) << std::endl; | |
68 | std::cout << p << std::endl; | |
69 | BOOST_TEST(p == make_vector(123, 456)); | |
70 | ||
71 | at_c<0>(p) = 6; | |
72 | at_c<1>(p) = 9; | |
73 | BOOST_TEST(p == make_vector(6, 9)); | |
74 | ||
75 | BOOST_STATIC_ASSERT(boost::fusion::result_of::size<Point>::value == 2); | |
76 | BOOST_STATIC_ASSERT(!boost::fusion::result_of::empty<Point>::value); | |
77 | ||
78 | BOOST_TEST(front(p) == 6); | |
79 | BOOST_TEST(back(p) == 9); | |
80 | } | |
81 | ||
82 | { | |
83 | vector<int, float> v1(4, 2.f); | |
84 | Point v2(5, 3); | |
85 | vector<long, double> v3(5, 4.); | |
86 | BOOST_TEST(v1 < v2); | |
87 | BOOST_TEST(v1 <= v2); | |
88 | BOOST_TEST(v2 > v1); | |
89 | BOOST_TEST(v2 >= v1); | |
90 | BOOST_TEST(v2 < v3); | |
91 | BOOST_TEST(v2 <= v3); | |
92 | BOOST_TEST(v3 > v2); | |
93 | BOOST_TEST(v3 >= v2); | |
94 | } | |
95 | ||
96 | { | |
97 | // conversion from Point to vector | |
98 | Point p(5, 3); | |
99 | vector<int, long> v(p); | |
100 | v = p; | |
101 | } | |
102 | ||
103 | { | |
104 | // conversion from Point to list | |
105 | Point p(5, 3); | |
106 | list<int, long> l(p); | |
107 | l = p; | |
108 | } | |
109 | ||
110 | { // begin/end | |
111 | using namespace boost::fusion; | |
112 | ||
113 | typedef boost::fusion::result_of::begin<ns::s<int> >::type b; | |
114 | typedef boost::fusion::result_of::end<ns::s<int> >::type e; | |
115 | // this fails | |
116 | BOOST_MPL_ASSERT((boost::is_same<boost::fusion::result_of::next<b>::type, e>)); | |
117 | } | |
118 | ||
119 | ||
120 | { | |
121 | Point p = make_list(5,3); | |
122 | BOOST_TEST(p == make_vector(5,3)); | |
123 | ||
124 | p = make_list(3,5); | |
125 | BOOST_TEST(p == make_vector(3,5)); | |
126 | } | |
127 | } | |
128 | ||
129 | int | |
130 | main() | |
131 | { | |
132 | run_test<cls::point<int, int> >(); // test non-template enclosing class | |
133 | run_test<tpl_cls<>::point<int, int> >(); // test template enclosing class | |
134 | ||
135 | return boost::report_errors(); | |
136 | } | |
137 |