]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/fusion/test/sequence/vector_n.cpp
1 /*=============================================================================
2 Copyright (c) 2001-2011 Joel de Guzman
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>
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>
19 #include <boost/type_traits/is_same.hpp>
20 #include <boost/type_traits/is_empty.hpp>
21 #include <boost/static_assert.hpp>
24 #include <boost/fusion/algorithm/transformation/push_back.hpp>
25 #include <boost/mpl/vector_c.hpp>
31 using namespace boost::fusion
;
32 using namespace boost
;
37 std::cout
<< "(): " << sizeof(vec
) << std::endl
;
38 std::cout
<< (boost::is_empty
<vector0
<> >::value
? "is empty" : "is not empty") << std::endl
;
42 typedef vector1
<int> type
;
44 BOOST_STATIC_ASSERT(boost::fusion::result_of::size
<type
>::value
== 1);
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
));
49 // prove that it is mutable
51 BOOST_TEST(at_c
<0>(vec
) == 987);
55 typedef vector1
<int> type
;
57 BOOST_TEST(at_c
<0>(vec
) == 123);
58 std::cout
<< "(int): " << sizeof(vec
) << std::endl
;
61 { // testing const vector
62 vector1
<short> const vec(999);
63 BOOST_TEST(at_c
<0>(vec
) == 999);
65 #ifdef FUSION_TEST_COMPILE_FAIL
71 vector1
<int> t1(123L); // try conversion from long to int
72 vector1
<double> t2(t1
); // try copy
77 typedef vector2
<int, char> type
;
79 BOOST_STATIC_ASSERT(boost::fusion::result_of::size
<type
>::value
== 2);
81 BOOST_TEST(at_c
<0>(vec
) == 0);
82 BOOST_TEST(at_c
<1>(vec
) == char());
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
));
89 typedef vector2
<int, char> type
;
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
;
97 vector2
<int, int> t1(123, 456);
98 vector2
<double, float> t2(t1
);
103 typedef vector3
<int, char, double> type
;
105 BOOST_STATIC_ASSERT(boost::fusion::result_of::size
<type
>::value
== 3);
107 BOOST_TEST(at_c
<0>(vec
) == 0);
108 BOOST_TEST(at_c
<1>(vec
) == char());
109 BOOST_TEST(at_c
<2>(vec
) == double());
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
));
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
;
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
;
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
;
138 typedef vector7
<bool, char, short, int, long, float, double> type
;
139 type
vec(false, 'x', 3, 4, 5, 6.f
, 7.0);
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);
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
;
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
;
167 int, int, int, int, int, int, int, int, int, int
168 , int, int, int, int, int, int, int, int, int, int> type
;
170 type vec
; // compile check only
171 std::cout
<< "vector20 of int: " << sizeof(vec
) << std::endl
;
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
;
180 type vec
; // compile check only
181 std::cout
<< "vector30 of int: " << sizeof(vec
) << std::endl
;
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
;
191 type vec
; // compile check only
192 std::cout
<< "vector40 of int: " << sizeof(vec
) << std::endl
;
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
;
203 type vec
; // compile check only
204 std::cout
<< "vector50 of int: " << sizeof(vec
) << std::endl
;
208 // testing copy and assign from a view
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);
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);
229 return boost::report_errors();