]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/fusion/test/sequence/vector_n.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / fusion / test / sequence / vector_n.cpp
1 /*=============================================================================
2 Copyright (c) 2001-2011 Joel de Guzman
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 #include <boost/detail/lightweight_test.hpp>
8 #include <boost/fusion/container/vector/vector10.hpp>
9 #include <boost/fusion/adapted/mpl.hpp>
10 #include <boost/fusion/sequence/intrinsic/size.hpp>
11 #include <boost/fusion/sequence/intrinsic/at.hpp>
12 #include <boost/fusion/sequence/intrinsic/value_at.hpp>
13
14 #include <boost/fusion/container/vector/vector20.hpp>
15 #include <boost/fusion/container/vector/vector30.hpp>
16 #include <boost/fusion/container/vector/vector40.hpp>
17 #include <boost/fusion/container/vector/vector50.hpp>
18
19 #include <boost/type_traits/is_same.hpp>
20 #include <boost/type_traits/is_empty.hpp>
21 #include <boost/static_assert.hpp>
22 #include <iostream>
23
24 #include <boost/fusion/algorithm/transformation/push_back.hpp>
25 #include <boost/mpl/vector_c.hpp>
26
27
28 int
29 main()
30 {
31 using namespace boost::fusion;
32 using namespace boost;
33
34 {
35 vector0<> vec;
36 (void) vec;
37 std::cout << "(): " << sizeof(vec) << std::endl;
38 std::cout << (boost::is_empty<vector0<> >::value ? "is empty" : "is not empty") << std::endl;
39 }
40
41 {
42 typedef vector1<int> type;
43 type vec;
44 BOOST_STATIC_ASSERT(boost::fusion::result_of::size<type>::value == 1);
45
46 BOOST_TEST(at_c<0>(vec) == 0);
47 BOOST_STATIC_ASSERT((boost::is_same<int, boost::fusion::result_of::value_at_c<type, 0>::type>::value));
48
49 // prove that it is mutable
50 at_c<0>(vec) = 987;
51 BOOST_TEST(at_c<0>(vec) == 987);
52 }
53
54 {
55 typedef vector1<int> type;
56 type vec(123);
57 BOOST_TEST(at_c<0>(vec) == 123);
58 std::cout << "(int): " << sizeof(vec) << std::endl;
59 }
60
61 { // testing const vector
62 vector1<short> const vec(999);
63 BOOST_TEST(at_c<0>(vec) == 999);
64
65 #ifdef FUSION_TEST_COMPILE_FAIL
66 at_c<0>(vec) = 321;
67 #endif
68 }
69
70 {
71 vector1<int> t1(123L); // try conversion from long to int
72 vector1<double> t2(t1); // try copy
73 (void)t2;
74 }
75
76 {
77 typedef vector2<int, char> type;
78 type vec;
79 BOOST_STATIC_ASSERT(boost::fusion::result_of::size<type>::value == 2);
80
81 BOOST_TEST(at_c<0>(vec) == 0);
82 BOOST_TEST(at_c<1>(vec) == char());
83
84 BOOST_STATIC_ASSERT((boost::is_same<int, boost::fusion::result_of::value_at_c<type, 0>::type>::value));
85 BOOST_STATIC_ASSERT((boost::is_same<char, boost::fusion::result_of::value_at_c<type, 1>::type>::value));
86 }
87
88 {
89 typedef vector2<int, char> type;
90 type vec(123, 'x');
91 BOOST_TEST(at_c<0>(vec) == 123);
92 BOOST_TEST(at_c<1>(vec) == 'x');
93 std::cout << "(int, char): " << sizeof(vec) << std::endl;
94 }
95
96 {
97 vector2<int, int> t1(123, 456);
98 vector2<double, float> t2(t1);
99 (void)t2;
100 }
101
102 {
103 typedef vector3<int, char, double> type;
104 type vec;
105 BOOST_STATIC_ASSERT(boost::fusion::result_of::size<type>::value == 3);
106
107 BOOST_TEST(at_c<0>(vec) == 0);
108 BOOST_TEST(at_c<1>(vec) == char());
109 BOOST_TEST(at_c<2>(vec) == double());
110
111 BOOST_STATIC_ASSERT((boost::is_same<int, boost::fusion::result_of::value_at_c<type, 0>::type>::value));
112 BOOST_STATIC_ASSERT((boost::is_same<char, boost::fusion::result_of::value_at_c<type, 1>::type>::value));
113 BOOST_STATIC_ASSERT((boost::is_same<double, boost::fusion::result_of::value_at_c<type, 2>::type>::value));
114 }
115
116 {
117 typedef vector3<int, char, double> type;
118 type vec(123, 'x', 123.456);
119 BOOST_TEST(at_c<0>(vec) == 123);
120 BOOST_TEST(at_c<1>(vec) == 'x');
121 BOOST_TEST(at_c<2>(vec) >= 123.455 && at_c<2>(vec) <= 123.457);
122 std::cout << "(int, char, double): " << sizeof(vec) << std::endl;
123 }
124
125 {
126 typedef vector4<int, char, double, bool> type;
127 type vec(123, 'x', 123.456, true);
128 std::cout << "(int, char, double, bool): " << sizeof(vec) << std::endl;
129 }
130
131 {
132 typedef vector4<int, char, bool, double> type;
133 type vec(123, 'x', true, 123.456);
134 std::cout << "(int, char, bool, double): " << sizeof(vec) << std::endl;
135 }
136
137 {
138 typedef vector7<bool, char, short, int, long, float, double> type;
139 type vec(false, 'x', 3, 4, 5, 6.f, 7.0);
140
141 BOOST_TEST(at_c<0>(vec) == false);
142 BOOST_TEST(at_c<1>(vec) == 'x');
143 BOOST_TEST(at_c<2>(vec) == 3);
144 BOOST_TEST(at_c<3>(vec) == 4);
145 BOOST_TEST(at_c<4>(vec) == 5);
146 BOOST_TEST(at_c<5>(vec) >= 5.9 && at_c<5>(vec) <= 6.1);
147 BOOST_TEST(at_c<6>(vec) >= 6.9 && at_c<6>(vec) <= 7.1);
148
149 BOOST_STATIC_ASSERT((boost::is_same<bool, boost::fusion::result_of::value_at_c<type, 0>::type>::value));
150 BOOST_STATIC_ASSERT((boost::is_same<char, boost::fusion::result_of::value_at_c<type, 1>::type>::value));
151 BOOST_STATIC_ASSERT((boost::is_same<short, boost::fusion::result_of::value_at_c<type, 2>::type>::value));
152 BOOST_STATIC_ASSERT((boost::is_same<int, boost::fusion::result_of::value_at_c<type, 3>::type>::value));
153 BOOST_STATIC_ASSERT((boost::is_same<long, boost::fusion::result_of::value_at_c<type, 4>::type>::value));
154 BOOST_STATIC_ASSERT((boost::is_same<float, boost::fusion::result_of::value_at_c<type, 5>::type>::value));
155 BOOST_STATIC_ASSERT((boost::is_same<double, boost::fusion::result_of::value_at_c<type, 6>::type>::value));
156 std::cout << "(bool, char, short, int, long, float, double): " << sizeof(vec) << std::endl;
157 }
158
159 {
160 typedef vector10<int, int, int, int, int, int, int, int, int, int> type;
161 type vec; // compile check only
162 std::cout << "vector10 of int: " << sizeof(vec) << std::endl;
163 }
164
165 {
166 typedef vector20<
167 int, int, int, int, int, int, int, int, int, int
168 , int, int, int, int, int, int, int, int, int, int> type;
169
170 type vec; // compile check only
171 std::cout << "vector20 of int: " << sizeof(vec) << std::endl;
172 }
173
174 {
175 typedef vector30<
176 int, int, int, int, int, int, int, int, int, int
177 , int, int, int, int, int, int, int, int, int, int
178 , int, int, int, int, int, int, int, int, int, int> type;
179
180 type vec; // compile check only
181 std::cout << "vector30 of int: " << sizeof(vec) << std::endl;
182 }
183
184 {
185 typedef vector40<
186 int, int, int, int, int, int, int, int, int, int
187 , int, int, int, int, int, int, int, int, int, int
188 , int, int, int, int, int, int, int, int, int, int
189 , int, int, int, int, int, int, int, int, int, int> type;
190
191 type vec; // compile check only
192 std::cout << "vector40 of int: " << sizeof(vec) << std::endl;
193 }
194
195 {
196 typedef vector50<
197 int, int, int, int, int, int, int, int, int, int
198 , int, int, int, int, int, int, int, int, int, int
199 , int, int, int, int, int, int, int, int, int, int
200 , int, int, int, int, int, int, int, int, int, int
201 , int, int, int, int, int, int, int, int, int, int> type;
202
203 type vec; // compile check only
204 std::cout << "vector50 of int: " << sizeof(vec) << std::endl;
205 }
206
207 {
208 // testing copy and assign from a view
209 vector0<> empty;
210 fusion::vector2<int, long> v(fusion::push_back(fusion::push_back(empty, 123), 456));
211 BOOST_TEST(at_c<0>(v) == 123);
212 BOOST_TEST(at_c<1>(v) == 456);
213 v = fusion::push_back(fusion::push_back(empty, 123), 456); // test assign
214 BOOST_TEST(at_c<0>(v) == 123);
215 BOOST_TEST(at_c<1>(v) == 456);
216 }
217
218 {
219 // testing copy and assign from a vector_c
220 mpl::vector_c<int, 123, 456> vec_c;
221 fusion::vector2<int, long> v(vec_c);
222 BOOST_TEST(at_c<0>(v) == 123);
223 BOOST_TEST(at_c<1>(v) == 456);
224 v = mpl::vector_c<int, 123, 456>(); // test assign
225 BOOST_TEST(at_c<0>(v) == 123);
226 BOOST_TEST(at_c<1>(v) == 456);
227 }
228
229 return boost::report_errors();
230 }
231