]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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_TPL_STRUCT( | |
21 | (X)(Y), | |
22 | (ns), | |
23 | point, | |
24 | (X, x) | |
25 | (Y, y) | |
26 | ) | |
27 | ||
28 | BOOST_FUSION_DEFINE_TPL_STRUCT((M), BOOST_PP_EMPTY(), s, (M, m)) | |
29 | ||
30 | BOOST_FUSION_DEFINE_TPL_STRUCT((M), BOOST_PP_EMPTY(), empty_struct, ) | |
31 | ||
32 | int | |
33 | main() | |
34 | { | |
35 | using namespace boost::fusion; | |
36 | ||
37 | typedef ns::point<int, int> point; | |
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<point>)); | |
92f5a8d4 | 45 | BOOST_STATIC_ASSERT(!traits::is_view<point>::value); |
7c673cae FG |
46 | 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<point>::value == 2); | |
58 | BOOST_STATIC_ASSERT(!boost::fusion::result_of::empty<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 | 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 point to vector | |
80 | point p(5, 3); | |
81 | vector<int, long> v(p); | |
82 | v = p; | |
83 | } | |
84 | ||
85 | { | |
86 | // conversion from point to list | |
87 | point p(5, 3); | |
88 | list<int, long> l(p); | |
89 | l = p; | |
90 | } | |
91 | ||
92 | { // begin/end | |
93 | using namespace boost::fusion; | |
94 | ||
95 | typedef boost::fusion::result_of::begin<s<int> >::type b; | |
96 | typedef boost::fusion::result_of::end<s<int> >::type e; | |
97 | // this fails | |
98 | BOOST_MPL_ASSERT((boost::is_same<boost::fusion::result_of::next<b>::type, e>)); | |
99 | } | |
100 | ||
101 | ||
102 | { | |
103 | point p = make_list(5,3); | |
104 | BOOST_TEST(p == make_vector(5,3)); | |
105 | ||
106 | p = make_list(3,5); | |
107 | BOOST_TEST(p == make_vector(3,5)); | |
108 | } | |
109 | ||
110 | return boost::report_errors(); | |
111 | } | |
112 |