1 // Boost.TypeErasure library
3 // Copyright 2011 Steven Watanabe
5 // Distributed under the Boost Software License Version 1.0. (See
6 // accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
11 #include <boost/type_erasure/any.hpp>
12 #include <boost/type_erasure/tuple.hpp>
13 #include <boost/type_erasure/builtin.hpp>
14 #include <boost/type_erasure/operators.hpp>
15 #include <boost/type_erasure/any_cast.hpp>
16 #include <boost/type_erasure/binding_of.hpp>
17 #include <boost/mpl/vector.hpp>
18 #include <boost/tuple/tuple.hpp>
21 #define BOOST_TEST_MAIN
22 #include <boost/test/unit_test.hpp>
24 using namespace boost::type_erasure
;
26 template<class T
= _self
>
27 struct common
: ::boost::mpl::vector
<
28 copy_constructible
<T
>,
32 BOOST_AUTO_TEST_CASE(test_implicit
) {
34 BOOST_CHECK_EQUAL(any_cast
<int>(x
), 1);
39 BOOST_AUTO_TEST_CASE(test_decay
) {
40 char array
[] = "Hello World!";
41 const char carray
[] = "Hello World!";
43 any
<common
<> > x1(array
);
44 any
<common
<> > y1(func
);
45 any
<common
<> > z1(carray
);
46 BOOST_CHECK_EQUAL(any_cast
<char *>(x1
), &array
[0]);
47 BOOST_CHECK(any_cast
<void(*)()>(y1
) == &func
);
48 BOOST_CHECK_EQUAL(any_cast
<const char *>(z1
), &carray
[0]);
50 any
<common
<> > x2(array
, make_binding
<boost::mpl::map
<boost::mpl::pair
<_self
, char *> > >());
51 any
<common
<> > y2(func
, make_binding
<boost::mpl::map
<boost::mpl::pair
<_self
, void(*)()> > >());
52 any
<common
<> > z2(carray
, make_binding
<boost::mpl::map
<boost::mpl::pair
<_self
, const char *> > >());
53 BOOST_CHECK_EQUAL(any_cast
<char *>(x2
), &array
[0]);
54 BOOST_CHECK(any_cast
<void(*)()>(y2
) == &func
);
55 BOOST_CHECK_EQUAL(any_cast
<const char *>(z2
), &carray
[0]);
57 static_binding
<boost::mpl::map
<boost::mpl::pair
<_self
, char *> > > bx3
;
58 static_binding
<boost::mpl::map
<boost::mpl::pair
<_self
, void (*)()> > > by3
;
59 static_binding
<boost::mpl::map
<boost::mpl::pair
<_self
, const char *> > > bz3
;
60 any
<common
<> > x3(array
, bx3
);
61 any
<common
<> > y3(func
, by3
);
62 any
<common
<> > z3(carray
, bz3
);
63 BOOST_CHECK_EQUAL(any_cast
<char *>(x3
), &array
[0]);
64 BOOST_CHECK(any_cast
<void(*)()>(y3
) == &func
);
65 BOOST_CHECK_EQUAL(any_cast
<const char *>(z3
), &carray
[0]);
72 #ifdef BOOST_NO_CXX11_RVALUE_REFERENCES
81 int make_arg_type
<int>() { return rvalue
; }
83 int make_arg_type
<int&>() { return lvalue
; }
85 int make_arg_type
<const int&>() { return const_lvalue
; }
87 enum { id_int
= 4, id_copy
= 8 };
89 std::vector
<int> make_vector() { return std::vector
<int>(); }
92 std::vector
<T
> make_vector(T t0
) {
93 std::vector
<T
> result
;
98 std::vector
<T
> make_vector(T t0
, T t1
) {
99 std::vector
<T
> result
;
100 result
.push_back(t0
);
101 result
.push_back(t1
);
110 test_class(const test_class
&)
111 : args(make_vector(const_lvalue
| id_copy
))
114 test_class(test_class
&)
115 : args(make_vector(lvalue
| id_copy
))
118 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
120 test_class(test_class
&&)
121 : args(make_vector(rvalue
| id_copy
))
126 : args(make_vector(t0
| make_arg_type
<T0
>()))
129 template<class T0
, class T1
>
130 test_class(T0
&& t0
, T1
&& t1
)
131 : args(make_vector(t0
| make_arg_type
<T0
>(), t1
| make_arg_type
<T1
>()))
137 : args(make_vector(i0
| lvalue
))
139 test_class(const int& i0
)
140 : args(make_vector(i0
| const_lvalue
))
142 test_class(int& i0
, int& i1
)
143 : args(make_vector(i0
| lvalue
, i1
| lvalue
))
145 test_class(int& i0
, const int& i1
)
146 : args(make_vector(i0
| lvalue
, i1
| const_lvalue
))
148 test_class(const int& i0
, int& i1
)
149 : args(make_vector(i0
| const_lvalue
, i1
| lvalue
))
151 test_class(const int& i0
, const int& i1
)
152 : args(make_vector(i0
| const_lvalue
, i1
| const_lvalue
))
156 std::vector
<int> args
;
160 struct make_arg_impl
;
163 struct make_arg_impl
<int>
171 template<class Concept
>
172 struct make_arg_impl
<binding
<Concept
> >
174 static binding
<Concept
> apply()
176 return make_binding
< ::boost::mpl::map
<
177 ::boost::mpl::pair
<_a
, test_class
>,
178 ::boost::mpl::pair
<_b
, int>
183 template<class Concept
>
184 struct make_arg_impl
<any
<Concept
, _a
> >
186 static any
<Concept
, _a
> apply()
188 return any
<Concept
, _a
>(
190 make_binding
< ::boost::mpl::map
<
191 ::boost::mpl::pair
<_a
, test_class
>,
192 ::boost::mpl::pair
<_b
, int>
197 template<class Concept
>
198 struct make_arg_impl
<any
<Concept
, _b
> >
200 static any
<Concept
, _b
> apply()
202 return any
<Concept
, _b
>(
204 make_binding
< ::boost::mpl::map
<
205 ::boost::mpl::pair
<_a
, test_class
>,
206 ::boost::mpl::pair
<_b
, int>
211 template<class Concept
, class T
>
212 struct make_arg_impl
<any
<Concept
, T
&> >
214 static any
<Concept
, T
&> apply()
216 return make_arg_impl
<any
<Concept
, T
>&>::apply();
220 template<class Concept
, class T
>
221 struct make_arg_impl
<any
<Concept
, const T
&> >
223 static any
<Concept
, const T
&> apply()
225 return make_arg_impl
<any
<Concept
, T
>&>::apply();
229 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
231 template<class Concept
, class T
>
232 struct make_arg_impl
<any
<Concept
, T
&&> >
234 static any
<Concept
, T
&&> apply()
236 return std::move(make_arg_impl
<any
<Concept
, T
>&>::apply());
243 struct make_arg_impl
<const T
> : make_arg_impl
<T
> {};
246 struct make_arg_impl
<T
&>
250 static T result
= make_arg_impl
<T
>::apply();
255 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
258 struct make_arg_impl
<T
&&>
262 static T result
= make_arg_impl
<T
>::apply();
263 return std::move(result
);
269 #ifdef BOOST_NO_CXX11_RVALUE_REFERENCES
274 return make_arg_impl
<T
>::apply();
282 return make_arg_impl
<T
&&>::apply();
287 int get_value(int i
) { return i
; }
289 int get_value(const T
& t
) { return any_cast
<int>(t
); }
291 template<class Sig
, class Args
>
294 template<class Concept
, class T
>
295 struct tester
<Concept
, void(T
)>
297 static std::vector
<int> apply()
299 any
<Concept
, _a
> x(make_arg
<T
>());
300 const test_class
& result
= any_cast
<const test_class
&>(x
);
305 template<class Concept
, class T0
, class T1
>
306 struct tester
<Concept
, void(T0
, T1
)>
308 static std::vector
<int> apply()
310 any
<Concept
, _a
> x(make_arg
<T0
>(), make_arg
<T1
>());
311 const test_class
& result
= any_cast
<const test_class
&>(x
);
316 template<class Concept
, class T0
, class T1
, class T2
>
317 struct tester
<Concept
, void(T0
, T1
, T2
)>
319 static std::vector
<int> apply()
321 any
<Concept
, _a
> x(make_arg
<T0
>(), make_arg
<T1
>(), make_arg
<T2
>());
322 const test_class
& result
= any_cast
<const test_class
&>(x
);
327 #define TEST_CONSTRUCT(sig, args, expected_) \
329 typedef ::boost::mpl::vector<\
334 std::vector<int> result = tester<C, void args>::apply();\
335 std::vector<int> expected = make_vector expected_;\
336 BOOST_CHECK_EQUAL_COLLECTIONS(result.begin(), result.end(), \
337 expected.begin(), expected.end());\
340 BOOST_AUTO_TEST_CASE(test_default
)
342 TEST_CONSTRUCT(_a(), (binding
<C
>), ());
343 TEST_CONSTRUCT(_a(), (binding
<C
>&), ());
344 TEST_CONSTRUCT(_a(), (const binding
<C
>&), ());
347 // test all forms of direct construction that take 1 argument
348 BOOST_AUTO_TEST_CASE(test_construct1
)
350 // construction from int
351 TEST_CONSTRUCT(_a(int&), (binding
<C
>, int&), (lvalue
| id_int
));
352 TEST_CONSTRUCT(_a(int&), (binding
<C
>&, int&), (lvalue
| id_int
));
353 TEST_CONSTRUCT(_a(int&), (const binding
<C
>&, int&), (lvalue
| id_int
));
355 TEST_CONSTRUCT(_a(const int&), (binding
<C
>, int), (const_lvalue
| id_int
));
356 TEST_CONSTRUCT(_a(const int&), (binding
<C
>, int&), (const_lvalue
| id_int
));
357 TEST_CONSTRUCT(_a(const int&), (binding
<C
>, const int&), (const_lvalue
| id_int
));
358 TEST_CONSTRUCT(_a(const int&), (binding
<C
>&, int), (const_lvalue
| id_int
));
359 TEST_CONSTRUCT(_a(const int&), (binding
<C
>&, int&), (const_lvalue
| id_int
));
360 TEST_CONSTRUCT(_a(const int&), (binding
<C
>&, const int&), (const_lvalue
| id_int
));
361 TEST_CONSTRUCT(_a(const int&), (const binding
<C
>&, int), (const_lvalue
| id_int
));
362 TEST_CONSTRUCT(_a(const int&), (const binding
<C
>&, int&), (const_lvalue
| id_int
));
363 TEST_CONSTRUCT(_a(const int&), (const binding
<C
>&, const int&), (const_lvalue
| id_int
));
365 TEST_CONSTRUCT(_a(int), (binding
<C
>, int), (rvalue
| id_int
));
366 TEST_CONSTRUCT(_a(int), (binding
<C
>, int&), (rvalue
| id_int
));
367 TEST_CONSTRUCT(_a(int), (binding
<C
>, const int&), (rvalue
| id_int
));
368 TEST_CONSTRUCT(_a(int), (binding
<C
>&, int), (rvalue
| id_int
));
369 TEST_CONSTRUCT(_a(int), (binding
<C
>&, int&), (rvalue
| id_int
));
370 TEST_CONSTRUCT(_a(int), (binding
<C
>&, const int&), (rvalue
| id_int
));
371 TEST_CONSTRUCT(_a(int), (const binding
<C
>&, int), (rvalue
| id_int
));
372 TEST_CONSTRUCT(_a(int), (const binding
<C
>&, int&), (rvalue
| id_int
));
373 TEST_CONSTRUCT(_a(int), (const binding
<C
>&, const int&), (rvalue
| id_int
));
375 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
376 TEST_CONSTRUCT(_a(int&&), (binding
<C
>, int), (rvalue
| id_int
));
377 TEST_CONSTRUCT(_a(int&&), (binding
<C
>&, int), (rvalue
| id_int
));
378 TEST_CONSTRUCT(_a(int&&), (const binding
<C
>&, int), (rvalue
| id_int
));
381 // Test same any type
383 #ifndef BOOST_NO_FUNCTION_REFERENCE_QUALIFIERS
384 // ambiguous with the copy constructor in C++03
385 TEST_CONSTRUCT(_a(_a
&), (any
<C
, _a
>&), (lvalue
| id_copy
));
386 TEST_CONSTRUCT(_a(_a
&), (binding
<C
>, any
<C
, _a
>&), (lvalue
| id_copy
));
387 TEST_CONSTRUCT(_a(_a
&), (binding
<C
>&, any
<C
, _a
>&), (lvalue
| id_copy
));
388 TEST_CONSTRUCT(_a(_a
&), (const binding
<C
>&, any
<C
, _a
>&), (lvalue
| id_copy
));
391 TEST_CONSTRUCT(_a(const _a
&), (any
<C
, _a
>), (const_lvalue
| id_copy
));
392 TEST_CONSTRUCT(_a(const _a
&), (any
<C
, _a
>&), (const_lvalue
| id_copy
));
393 TEST_CONSTRUCT(_a(const _a
&), (const any
<C
, _a
>&), (const_lvalue
| id_copy
));
394 TEST_CONSTRUCT(_a(const _a
&), (binding
<C
>, any
<C
, _a
>), (const_lvalue
| id_copy
));
395 TEST_CONSTRUCT(_a(const _a
&), (binding
<C
>, any
<C
, _a
>&), (const_lvalue
| id_copy
));
396 TEST_CONSTRUCT(_a(const _a
&), (binding
<C
>, const any
<C
, _a
>&), (const_lvalue
| id_copy
));
397 TEST_CONSTRUCT(_a(const _a
&), (binding
<C
>&, any
<C
, _a
>), (const_lvalue
| id_copy
));
398 TEST_CONSTRUCT(_a(const _a
&), (binding
<C
>&, any
<C
, _a
>&), (const_lvalue
| id_copy
));
399 TEST_CONSTRUCT(_a(const _a
&), (binding
<C
>&, const any
<C
, _a
>&), (const_lvalue
| id_copy
));
400 TEST_CONSTRUCT(_a(const _a
&), (const binding
<C
>&, any
<C
, _a
>), (const_lvalue
| id_copy
));
401 TEST_CONSTRUCT(_a(const _a
&), (const binding
<C
>&, any
<C
, _a
>&), (const_lvalue
| id_copy
));
402 TEST_CONSTRUCT(_a(const _a
&), (const binding
<C
>&, const any
<C
, _a
>&), (const_lvalue
| id_copy
));
404 #ifndef BOOST_NO_FUNCTION_REFERENCE_QUALIFIERS
406 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
407 TEST_CONSTRUCT(_a(_a
&&), (any
<C
, _a
>), (rvalue
| id_copy
));
408 TEST_CONSTRUCT(_a(_a
&&), (binding
<C
>, any
<C
, _a
>), (rvalue
| id_copy
));
409 TEST_CONSTRUCT(_a(_a
&&), (binding
<C
>&, any
<C
, _a
>), (rvalue
| id_copy
));
410 TEST_CONSTRUCT(_a(_a
&&), (const binding
<C
>&, any
<C
, _a
>), (rvalue
| id_copy
));
415 // test other any type
416 TEST_CONSTRUCT(_a(_b
&), (any
<C
, _b
>&), (lvalue
| id_int
));
417 TEST_CONSTRUCT(_a(_b
&), (binding
<C
>, any
<C
, _b
>&), (lvalue
| id_int
));
418 TEST_CONSTRUCT(_a(_b
&), (binding
<C
>&, any
<C
, _b
>&), (lvalue
| id_int
));
419 TEST_CONSTRUCT(_a(_b
&), (const binding
<C
>&, any
<C
, _b
>&), (lvalue
| id_int
));
421 TEST_CONSTRUCT(_a(const _b
&), (any
<C
, _b
>), (const_lvalue
| id_int
));
422 TEST_CONSTRUCT(_a(const _b
&), (any
<C
, _b
>&), (const_lvalue
| id_int
));
423 TEST_CONSTRUCT(_a(const _b
&), (const any
<C
, _b
>&), (const_lvalue
| id_int
));
424 TEST_CONSTRUCT(_a(const _b
&), (binding
<C
>, any
<C
, _b
>), (const_lvalue
| id_int
));
425 TEST_CONSTRUCT(_a(const _b
&), (binding
<C
>, any
<C
, _b
>&), (const_lvalue
| id_int
));
426 TEST_CONSTRUCT(_a(const _b
&), (binding
<C
>, const any
<C
, _b
>&), (const_lvalue
| id_int
));
427 TEST_CONSTRUCT(_a(const _b
&), (binding
<C
>&, any
<C
, _b
>), (const_lvalue
| id_int
));
428 TEST_CONSTRUCT(_a(const _b
&), (binding
<C
>&, any
<C
, _b
>&), (const_lvalue
| id_int
));
429 TEST_CONSTRUCT(_a(const _b
&), (binding
<C
>&, const any
<C
, _b
>&), (const_lvalue
| id_int
));
430 TEST_CONSTRUCT(_a(const _b
&), (const binding
<C
>&, any
<C
, _b
>), (const_lvalue
| id_int
));
431 TEST_CONSTRUCT(_a(const _b
&), (const binding
<C
>&, any
<C
, _b
>&), (const_lvalue
| id_int
));
432 TEST_CONSTRUCT(_a(const _b
&), (const binding
<C
>&, const any
<C
, _b
>&), (const_lvalue
| id_int
));
434 TEST_CONSTRUCT(_a(_b
), (any
<C
, _b
>), (rvalue
| id_int
));
435 TEST_CONSTRUCT(_a(_b
), (any
<C
, _b
>&), (rvalue
| id_int
));
436 TEST_CONSTRUCT(_a(_b
), (const any
<C
, _b
>&), (rvalue
| id_int
));
437 TEST_CONSTRUCT(_a(_b
), (binding
<C
>, any
<C
, _b
>), (rvalue
| id_int
));
438 TEST_CONSTRUCT(_a(_b
), (binding
<C
>, any
<C
, _b
>&), (rvalue
| id_int
));
439 TEST_CONSTRUCT(_a(_b
), (binding
<C
>, const any
<C
, _b
>&), (rvalue
| id_int
));
440 TEST_CONSTRUCT(_a(_b
), (binding
<C
>&, any
<C
, _b
>), (rvalue
| id_int
));
441 TEST_CONSTRUCT(_a(_b
), (binding
<C
>&, any
<C
, _b
>&), (rvalue
| id_int
));
442 TEST_CONSTRUCT(_a(_b
), (binding
<C
>&, const any
<C
, _b
>&), (rvalue
| id_int
));
443 TEST_CONSTRUCT(_a(_b
), (const binding
<C
>&, any
<C
, _b
>), (rvalue
| id_int
));
444 TEST_CONSTRUCT(_a(_b
), (const binding
<C
>&, any
<C
, _b
>&), (rvalue
| id_int
));
445 TEST_CONSTRUCT(_a(_b
), (const binding
<C
>&, const any
<C
, _b
>&), (rvalue
| id_int
));
447 #ifndef BOOST_NO_FUNCTION_REFERENCE_QUALIFIERS
449 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
450 TEST_CONSTRUCT(_a(_b
&&), (any
<C
, _b
>), (rvalue
| id_int
));
451 TEST_CONSTRUCT(_a(_b
&&), (binding
<C
>, any
<C
, _b
>), (rvalue
| id_int
));
452 TEST_CONSTRUCT(_a(_b
&&), (binding
<C
>&, any
<C
, _b
>), (rvalue
| id_int
));
453 TEST_CONSTRUCT(_a(_b
&&), (const binding
<C
>&, any
<C
, _b
>), (rvalue
| id_int
));
458 // test any reference type
459 TEST_CONSTRUCT(_a(_b
&), (any
<C
, _b
&>), (lvalue
| id_int
));
460 TEST_CONSTRUCT(_a(_b
&), (any
<C
, _b
&>&), (lvalue
| id_int
));
461 TEST_CONSTRUCT(_a(_b
&), (const any
<C
, _b
&>&), (lvalue
| id_int
));
462 TEST_CONSTRUCT(_a(_b
&), (binding
<C
>, any
<C
, _b
&>), (lvalue
| id_int
));
463 TEST_CONSTRUCT(_a(_b
&), (binding
<C
>, any
<C
, _b
&>&), (lvalue
| id_int
));
464 TEST_CONSTRUCT(_a(_b
&), (binding
<C
>, const any
<C
, _b
&>&), (lvalue
| id_int
));
465 TEST_CONSTRUCT(_a(_b
&), (binding
<C
>&, any
<C
, _b
&>), (lvalue
| id_int
));
466 TEST_CONSTRUCT(_a(_b
&), (binding
<C
>&, any
<C
, _b
&>&), (lvalue
| id_int
));
467 TEST_CONSTRUCT(_a(_b
&), (binding
<C
>&, const any
<C
, _b
&>&), (lvalue
| id_int
));
468 TEST_CONSTRUCT(_a(_b
&), (const binding
<C
>&, any
<C
, _b
&>), (lvalue
| id_int
));
469 TEST_CONSTRUCT(_a(_b
&), (const binding
<C
>&, any
<C
, _b
&>&), (lvalue
| id_int
));
470 TEST_CONSTRUCT(_a(_b
&), (const binding
<C
>&, const any
<C
, _b
&>&), (lvalue
| id_int
));
472 TEST_CONSTRUCT(_a(const _b
&), (any
<C
, _b
&>), (const_lvalue
| id_int
));
473 TEST_CONSTRUCT(_a(const _b
&), (any
<C
, _b
&>&), (const_lvalue
| id_int
));
474 TEST_CONSTRUCT(_a(const _b
&), (const any
<C
, _b
&>&), (const_lvalue
| id_int
));
475 TEST_CONSTRUCT(_a(const _b
&), (binding
<C
>, any
<C
, _b
&>), (const_lvalue
| id_int
));
476 TEST_CONSTRUCT(_a(const _b
&), (binding
<C
>, any
<C
, _b
&>&), (const_lvalue
| id_int
));
477 TEST_CONSTRUCT(_a(const _b
&), (binding
<C
>, const any
<C
, _b
&>&), (const_lvalue
| id_int
));
478 TEST_CONSTRUCT(_a(const _b
&), (binding
<C
>&, any
<C
, _b
&>), (const_lvalue
| id_int
));
479 TEST_CONSTRUCT(_a(const _b
&), (binding
<C
>&, any
<C
, _b
&>&), (const_lvalue
| id_int
));
480 TEST_CONSTRUCT(_a(const _b
&), (binding
<C
>&, const any
<C
, _b
&>&), (const_lvalue
| id_int
));
481 TEST_CONSTRUCT(_a(const _b
&), (const binding
<C
>&, any
<C
, _b
&>), (const_lvalue
| id_int
));
482 TEST_CONSTRUCT(_a(const _b
&), (const binding
<C
>&, any
<C
, _b
&>&), (const_lvalue
| id_int
));
483 TEST_CONSTRUCT(_a(const _b
&), (const binding
<C
>&, const any
<C
, _b
&>&), (const_lvalue
| id_int
));
485 TEST_CONSTRUCT(_a(_b
), (any
<C
, _b
&>), (rvalue
| id_int
));
486 TEST_CONSTRUCT(_a(_b
), (any
<C
, _b
&>&), (rvalue
| id_int
));
487 TEST_CONSTRUCT(_a(_b
), (const any
<C
, _b
&>&), (rvalue
| id_int
));
488 TEST_CONSTRUCT(_a(_b
), (binding
<C
>, any
<C
, _b
&>), (rvalue
| id_int
));
489 TEST_CONSTRUCT(_a(_b
), (binding
<C
>, any
<C
, _b
&>&), (rvalue
| id_int
));
490 TEST_CONSTRUCT(_a(_b
), (binding
<C
>, const any
<C
, _b
&>&), (rvalue
| id_int
));
491 TEST_CONSTRUCT(_a(_b
), (binding
<C
>&, any
<C
, _b
&>), (rvalue
| id_int
));
492 TEST_CONSTRUCT(_a(_b
), (binding
<C
>&, any
<C
, _b
&>&), (rvalue
| id_int
));
493 TEST_CONSTRUCT(_a(_b
), (binding
<C
>&, const any
<C
, _b
&>&), (rvalue
| id_int
));
494 TEST_CONSTRUCT(_a(_b
), (const binding
<C
>&, any
<C
, _b
&>), (rvalue
| id_int
));
495 TEST_CONSTRUCT(_a(_b
), (const binding
<C
>&, any
<C
, _b
&>&), (rvalue
| id_int
));
496 TEST_CONSTRUCT(_a(_b
), (const binding
<C
>&, const any
<C
, _b
&>&), (rvalue
| id_int
));
498 // test const any reference type
499 TEST_CONSTRUCT(_a(const _b
&), (any
<C
, const _b
&>), (const_lvalue
| id_int
));
500 TEST_CONSTRUCT(_a(const _b
&), (any
<C
, const _b
&>&), (const_lvalue
| id_int
));
501 TEST_CONSTRUCT(_a(const _b
&), (const any
<C
, const _b
&>&), (const_lvalue
| id_int
));
502 TEST_CONSTRUCT(_a(const _b
&), (binding
<C
>, any
<C
, const _b
&>), (const_lvalue
| id_int
));
503 TEST_CONSTRUCT(_a(const _b
&), (binding
<C
>, any
<C
, const _b
&>&), (const_lvalue
| id_int
));
504 TEST_CONSTRUCT(_a(const _b
&), (binding
<C
>, const any
<C
, const _b
&>&), (const_lvalue
| id_int
));
505 TEST_CONSTRUCT(_a(const _b
&), (binding
<C
>&, any
<C
, const _b
&>), (const_lvalue
| id_int
));
506 TEST_CONSTRUCT(_a(const _b
&), (binding
<C
>&, any
<C
, const _b
&>&), (const_lvalue
| id_int
));
507 TEST_CONSTRUCT(_a(const _b
&), (binding
<C
>&, const any
<C
, const _b
&>&), (const_lvalue
| id_int
));
508 TEST_CONSTRUCT(_a(const _b
&), (const binding
<C
>&, any
<C
, const _b
&>), (const_lvalue
| id_int
));
509 TEST_CONSTRUCT(_a(const _b
&), (const binding
<C
>&, any
<C
, const _b
&>&), (const_lvalue
| id_int
));
510 TEST_CONSTRUCT(_a(const _b
&), (const binding
<C
>&, const any
<C
, const _b
&>&), (const_lvalue
| id_int
));
512 TEST_CONSTRUCT(_a(_b
), (any
<C
, const _b
&>), (rvalue
| id_int
));
513 TEST_CONSTRUCT(_a(_b
), (any
<C
, const _b
&>&), (rvalue
| id_int
));
514 TEST_CONSTRUCT(_a(_b
), (const any
<C
, const _b
&>&), (rvalue
| id_int
));
515 TEST_CONSTRUCT(_a(_b
), (binding
<C
>, any
<C
, const _b
&>), (rvalue
| id_int
));
516 TEST_CONSTRUCT(_a(_b
), (binding
<C
>, any
<C
, const _b
&>&), (rvalue
| id_int
));
517 TEST_CONSTRUCT(_a(_b
), (binding
<C
>, const any
<C
, const _b
&>&), (rvalue
| id_int
));
518 TEST_CONSTRUCT(_a(_b
), (binding
<C
>&, any
<C
, const _b
&>), (rvalue
| id_int
));
519 TEST_CONSTRUCT(_a(_b
), (binding
<C
>&, any
<C
, const _b
&>&), (rvalue
| id_int
));
520 TEST_CONSTRUCT(_a(_b
), (binding
<C
>&, const any
<C
, const _b
&>&), (rvalue
| id_int
));
521 TEST_CONSTRUCT(_a(_b
), (const binding
<C
>&, any
<C
, const _b
&>), (rvalue
| id_int
));
522 TEST_CONSTRUCT(_a(_b
), (const binding
<C
>&, any
<C
, const _b
&>&), (rvalue
| id_int
));
523 TEST_CONSTRUCT(_a(_b
), (const binding
<C
>&, const any
<C
, const _b
&>&), (rvalue
| id_int
));
525 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
527 // test any rvalue reference type
528 TEST_CONSTRUCT(_a(const _b
&), (any
<C
, _b
&&>), (const_lvalue
| id_int
));
529 TEST_CONSTRUCT(_a(const _b
&), (any
<C
, _b
&&>&), (const_lvalue
| id_int
));
530 TEST_CONSTRUCT(_a(const _b
&), (const any
<C
, _b
&&>&), (const_lvalue
| id_int
));
531 TEST_CONSTRUCT(_a(const _b
&), (binding
<C
>, any
<C
, _b
&&>), (const_lvalue
| id_int
));
532 TEST_CONSTRUCT(_a(const _b
&), (binding
<C
>, any
<C
, _b
&&>&), (const_lvalue
| id_int
));
533 TEST_CONSTRUCT(_a(const _b
&), (binding
<C
>, const any
<C
, _b
&&>&), (const_lvalue
| id_int
));
534 TEST_CONSTRUCT(_a(const _b
&), (binding
<C
>&, any
<C
, _b
&&>), (const_lvalue
| id_int
));
535 TEST_CONSTRUCT(_a(const _b
&), (binding
<C
>&, any
<C
, _b
&&>&), (const_lvalue
| id_int
));
536 TEST_CONSTRUCT(_a(const _b
&), (binding
<C
>&, const any
<C
, _b
&&>&), (const_lvalue
| id_int
));
537 TEST_CONSTRUCT(_a(const _b
&), (const binding
<C
>&, any
<C
, _b
&&>), (const_lvalue
| id_int
));
538 TEST_CONSTRUCT(_a(const _b
&), (const binding
<C
>&, any
<C
, _b
&&>&), (const_lvalue
| id_int
));
539 TEST_CONSTRUCT(_a(const _b
&), (const binding
<C
>&, const any
<C
, _b
&&>&), (const_lvalue
| id_int
));
541 TEST_CONSTRUCT(_a(_b
), (any
<C
, _b
&&>), (rvalue
| id_int
));
542 TEST_CONSTRUCT(_a(_b
), (any
<C
, _b
&&>&), (rvalue
| id_int
));
543 TEST_CONSTRUCT(_a(_b
), (const any
<C
, _b
&&>&), (rvalue
| id_int
));
544 TEST_CONSTRUCT(_a(_b
), (binding
<C
>, any
<C
, _b
&&>), (rvalue
| id_int
));
545 TEST_CONSTRUCT(_a(_b
), (binding
<C
>, any
<C
, _b
&&>&), (rvalue
| id_int
));
546 TEST_CONSTRUCT(_a(_b
), (binding
<C
>, const any
<C
, _b
&&>&), (rvalue
| id_int
));
547 TEST_CONSTRUCT(_a(_b
), (binding
<C
>&, any
<C
, _b
&&>), (rvalue
| id_int
));
548 TEST_CONSTRUCT(_a(_b
), (binding
<C
>&, any
<C
, _b
&&>&), (rvalue
| id_int
));
549 TEST_CONSTRUCT(_a(_b
), (binding
<C
>&, const any
<C
, _b
&&>&), (rvalue
| id_int
));
550 TEST_CONSTRUCT(_a(_b
), (const binding
<C
>&, any
<C
, _b
&&>), (rvalue
| id_int
));
551 TEST_CONSTRUCT(_a(_b
), (const binding
<C
>&, any
<C
, _b
&&>&), (rvalue
| id_int
));
552 TEST_CONSTRUCT(_a(_b
), (const binding
<C
>&, const any
<C
, _b
&&>&), (rvalue
| id_int
));
554 TEST_CONSTRUCT(_a(_b
&&), (any
<C
, _b
&&>), (rvalue
| id_int
));
555 TEST_CONSTRUCT(_a(_b
&&), (any
<C
, _b
&&>&), (rvalue
| id_int
));
556 TEST_CONSTRUCT(_a(_b
&&), (const any
<C
, _b
&&>&), (rvalue
| id_int
));
557 TEST_CONSTRUCT(_a(_b
&&), (binding
<C
>, any
<C
, _b
&&>), (rvalue
| id_int
));
558 TEST_CONSTRUCT(_a(_b
&&), (binding
<C
>, any
<C
, _b
&&>&), (rvalue
| id_int
));
559 TEST_CONSTRUCT(_a(_b
&&), (binding
<C
>, const any
<C
, _b
&&>&), (rvalue
| id_int
));
560 TEST_CONSTRUCT(_a(_b
&&), (binding
<C
>&, any
<C
, _b
&&>), (rvalue
| id_int
));
561 TEST_CONSTRUCT(_a(_b
&&), (binding
<C
>&, any
<C
, _b
&&>&), (rvalue
| id_int
));
562 TEST_CONSTRUCT(_a(_b
&&), (binding
<C
>&, const any
<C
, _b
&&>&), (rvalue
| id_int
));
563 TEST_CONSTRUCT(_a(_b
&&), (const binding
<C
>&, any
<C
, _b
&&>), (rvalue
| id_int
));
564 TEST_CONSTRUCT(_a(_b
&&), (const binding
<C
>&, any
<C
, _b
&&>&), (rvalue
| id_int
));
565 TEST_CONSTRUCT(_a(_b
&&), (const binding
<C
>&, const any
<C
, _b
&&>&), (rvalue
| id_int
));
571 // test constructors with 2 parameters
572 BOOST_AUTO_TEST_CASE(test_construct2
)
574 TEST_CONSTRUCT(_a(int, int), (binding
<C
>, int, int), (rvalue
| id_int
, rvalue
| id_int
));
575 TEST_CONSTRUCT(_a(int, int), (binding
<C
>, int, int&), (rvalue
| id_int
, rvalue
| id_int
));
576 TEST_CONSTRUCT(_a(int, int), (binding
<C
>, int, const int&), (rvalue
| id_int
, rvalue
| id_int
));
577 TEST_CONSTRUCT(_a(int, int), (binding
<C
>, int&, int), (rvalue
| id_int
, rvalue
| id_int
));
578 TEST_CONSTRUCT(_a(int, int), (binding
<C
>, int&, int&), (rvalue
| id_int
, rvalue
| id_int
));
579 TEST_CONSTRUCT(_a(int, int), (binding
<C
>, int&, const int&), (rvalue
| id_int
, rvalue
| id_int
));
580 TEST_CONSTRUCT(_a(int, int), (binding
<C
>, const int&, int), (rvalue
| id_int
, rvalue
| id_int
));
581 TEST_CONSTRUCT(_a(int, int), (binding
<C
>, const int&, int&), (rvalue
| id_int
, rvalue
| id_int
));
582 TEST_CONSTRUCT(_a(int, int), (binding
<C
>, const int&, const int&), (rvalue
| id_int
, rvalue
| id_int
));
583 TEST_CONSTRUCT(_a(int, int), (binding
<C
>&, int, int), (rvalue
| id_int
, rvalue
| id_int
));
584 TEST_CONSTRUCT(_a(int, int), (binding
<C
>&, int, int&), (rvalue
| id_int
, rvalue
| id_int
));
585 TEST_CONSTRUCT(_a(int, int), (binding
<C
>&, int, const int&), (rvalue
| id_int
, rvalue
| id_int
));
586 TEST_CONSTRUCT(_a(int, int), (binding
<C
>&, int&, int), (rvalue
| id_int
, rvalue
| id_int
));
587 TEST_CONSTRUCT(_a(int, int), (binding
<C
>&, int&, int&), (rvalue
| id_int
, rvalue
| id_int
));
588 TEST_CONSTRUCT(_a(int, int), (binding
<C
>&, int&, const int&), (rvalue
| id_int
, rvalue
| id_int
));
589 TEST_CONSTRUCT(_a(int, int), (binding
<C
>&, const int&, int), (rvalue
| id_int
, rvalue
| id_int
));
590 TEST_CONSTRUCT(_a(int, int), (binding
<C
>&, const int&, int&), (rvalue
| id_int
, rvalue
| id_int
));
591 TEST_CONSTRUCT(_a(int, int), (binding
<C
>&, const int&, const int&), (rvalue
| id_int
, rvalue
| id_int
));
592 TEST_CONSTRUCT(_a(int, int), (const binding
<C
>&, int, int), (rvalue
| id_int
, rvalue
| id_int
));
593 TEST_CONSTRUCT(_a(int, int), (const binding
<C
>&, int, int&), (rvalue
| id_int
, rvalue
| id_int
));
594 TEST_CONSTRUCT(_a(int, int), (const binding
<C
>&, int, const int&), (rvalue
| id_int
, rvalue
| id_int
));
595 TEST_CONSTRUCT(_a(int, int), (const binding
<C
>&, int&, int), (rvalue
| id_int
, rvalue
| id_int
));
596 TEST_CONSTRUCT(_a(int, int), (const binding
<C
>&, int&, int&), (rvalue
| id_int
, rvalue
| id_int
));
597 TEST_CONSTRUCT(_a(int, int), (const binding
<C
>&, int&, const int&), (rvalue
| id_int
, rvalue
| id_int
));
598 TEST_CONSTRUCT(_a(int, int), (const binding
<C
>&, const int&, int), (rvalue
| id_int
, rvalue
| id_int
));
599 TEST_CONSTRUCT(_a(int, int), (const binding
<C
>&, const int&, int&), (rvalue
| id_int
, rvalue
| id_int
));
600 TEST_CONSTRUCT(_a(int, int), (const binding
<C
>&, const int&, const int&), (rvalue
| id_int
, rvalue
| id_int
));
603 BOOST_AUTO_TEST_CASE(test_overload
)
605 typedef ::boost::mpl::vector
<
608 constructible
<_a(_b
)>,
609 constructible
<_a(std::size_t)>
611 typedef ::boost::mpl::map
<
612 ::boost::mpl::pair
<_a
, std::vector
<int> >,
613 ::boost::mpl::pair
<_b
, std::size_t>
615 binding
<test_concept
> table
= make_binding
<types
>();
616 any
<test_concept
, _b
> x(static_cast<std::size_t>(10), make_binding
<types
>());
617 any
<test_concept
, _a
> y(x
);
618 any
<test_concept
, _a
> z(table
, 17);
619 std::vector
<int> vec1(any_cast
<std::vector
<int> >(y
));
620 BOOST_CHECK_EQUAL(vec1
.size(), 10u);
621 std::vector
<int> vec2(any_cast
<std::vector
<int> >(z
));
622 BOOST_CHECK_EQUAL(vec2
.size(), 17u);
626 T
as_rvalue(const T
& arg
) { return arg
; }
628 const T
& as_const(const T
& arg
) { return arg
; }
630 BOOST_AUTO_TEST_CASE(test_from_int_with_binding
)
632 typedef ::boost::mpl::vector
<common
<> > test_concept
;
633 static_binding
<boost::mpl::map
<boost::mpl::pair
<_self
, int> > > binding
=
634 make_binding
<boost::mpl::map
<boost::mpl::pair
<_self
, int> > >();
637 any
<test_concept
> x1(value
, binding
);
638 BOOST_CHECK_EQUAL(any_cast
<int>(x1
), 4);
639 any
<test_concept
> x2(value
, as_rvalue(binding
));
640 BOOST_CHECK_EQUAL(any_cast
<int>(x2
), 4);
641 any
<test_concept
> x3(value
, as_const(binding
));
642 BOOST_CHECK_EQUAL(any_cast
<int>(x3
), 4);
644 any
<test_concept
> y1(as_rvalue(value
), binding
);
645 BOOST_CHECK_EQUAL(any_cast
<int>(y1
), 4);
646 any
<test_concept
> y2(as_rvalue(value
), as_rvalue(binding
));
647 BOOST_CHECK_EQUAL(any_cast
<int>(y2
), 4);
648 any
<test_concept
> y3(as_rvalue(value
), as_const(binding
));
649 BOOST_CHECK_EQUAL(any_cast
<int>(y3
), 4);
651 any
<test_concept
> z1(as_const(value
), binding
);
652 BOOST_CHECK_EQUAL(any_cast
<int>(z1
), 4);
653 any
<test_concept
> z2(as_const(value
), as_rvalue(binding
));
654 BOOST_CHECK_EQUAL(any_cast
<int>(z2
), 4);
655 any
<test_concept
> z3(as_const(value
), as_const(binding
));
656 BOOST_CHECK_EQUAL(any_cast
<int>(z3
), 4);
659 BOOST_AUTO_TEST_CASE(test_copy
)
661 typedef ::boost::mpl::vector
<common
<> > test_concept
;
662 any
<test_concept
> x(4);
663 BOOST_CHECK_EQUAL(any_cast
<int>(x
), 4);
664 any
<test_concept
> y(x
);
665 BOOST_CHECK_EQUAL(any_cast
<int>(y
), 4);
666 any
<test_concept
> z(as_rvalue(x
));
667 BOOST_CHECK_EQUAL(any_cast
<int>(z
), 4);
668 any
<test_concept
> w(as_const(x
));
669 BOOST_CHECK_EQUAL(any_cast
<int>(w
), 4);
672 BOOST_AUTO_TEST_CASE(test_copy_implicit
)
674 typedef ::boost::mpl::vector
<common
<>, common
<_a
> > test_concept
;
675 any
<test_concept
> x(4, make_binding
< ::boost::mpl::map
< ::boost::mpl::pair
<_self
, int>, ::boost::mpl::pair
<_a
, int> > >());
676 BOOST_CHECK_EQUAL(any_cast
<int>(x
), 4);
678 any
<test_concept
> y
= x
;
679 BOOST_CHECK_EQUAL(any_cast
<int>(y
), 4);
680 any
<test_concept
> z
= as_rvalue(x
);
681 BOOST_CHECK_EQUAL(any_cast
<int>(z
), 4);
682 any
<test_concept
> w
= as_const(x
);
683 BOOST_CHECK_EQUAL(any_cast
<int>(w
), 4);
686 BOOST_AUTO_TEST_CASE(test_convert
)
688 typedef ::boost::mpl::vector
<common
<>, incrementable
<> > src_concept
;
689 typedef ::boost::mpl::vector
<common
<> > dst_concept
;
690 any
<src_concept
> x(4);
691 BOOST_CHECK_EQUAL(any_cast
<int>(x
), 4);
692 any
<dst_concept
> y(x
);
693 BOOST_CHECK_EQUAL(any_cast
<int>(y
), 4);
694 any
<dst_concept
> z
= as_rvalue(x
);
695 BOOST_CHECK_EQUAL(any_cast
<int>(z
), 4);
696 any
<dst_concept
> w
= as_const(x
);
697 BOOST_CHECK_EQUAL(any_cast
<int>(w
), 4);
700 BOOST_AUTO_TEST_CASE(test_rebind
)
702 typedef ::boost::mpl::vector
<common
<> > src_concept
;
703 typedef ::boost::mpl::vector
<common
<_a
> > dst_concept
;
704 any
<src_concept
> x(4);
705 BOOST_CHECK_EQUAL(any_cast
<int>(x
), 4);
706 any
<dst_concept
, _a
> y
= x
;
707 BOOST_CHECK_EQUAL(any_cast
<int>(y
), 4);
708 any
<dst_concept
, _a
> z
= as_rvalue(x
);
709 BOOST_CHECK_EQUAL(any_cast
<int>(z
), 4);
710 any
<dst_concept
, _a
> w
= as_const(x
);
711 BOOST_CHECK_EQUAL(any_cast
<int>(w
), 4);
714 BOOST_AUTO_TEST_CASE(test_rebind_and_convert
)
716 typedef ::boost::mpl::vector
<common
<>, incrementable
<> > src_concept
;
717 typedef ::boost::mpl::vector
<common
<_a
> > dst_concept
;
718 any
<src_concept
> x(4);
719 BOOST_CHECK_EQUAL(any_cast
<int>(x
), 4);
720 any
<dst_concept
, _a
> y(x
);
721 BOOST_CHECK_EQUAL(any_cast
<int>(y
), 4);
722 any
<dst_concept
, _a
> z
= as_rvalue(x
);
723 BOOST_CHECK_EQUAL(any_cast
<int>(z
), 4);
724 any
<dst_concept
, _a
> w
= as_const(x
);
725 BOOST_CHECK_EQUAL(any_cast
<int>(w
), 4);
728 BOOST_AUTO_TEST_CASE(test_rebind_and_convert_with_binding
)
730 typedef ::boost::mpl::vector
<common
<>, incrementable
<> > src_concept
;
731 typedef ::boost::mpl::vector
<common
<_a
> > dst_concept
;
732 typedef ::boost::mpl::map
<boost::mpl::pair
<_a
, _self
> > map
;
733 typedef ::boost::mpl::map
<boost::mpl::pair
<_a
, int> > types
;
735 static_binding
<map
> s_table(make_binding
<map
>());
736 binding
<dst_concept
> table(make_binding
<types
>());
738 any
<src_concept
> x(4);
739 BOOST_CHECK_EQUAL(any_cast
<int>(x
), 4);
742 any
<dst_concept
, _a
> y1(x
, s_table
);
743 BOOST_CHECK_EQUAL(any_cast
<int>(y1
), 4);
744 any
<dst_concept
, _a
> y2(x
, as_rvalue(s_table
));
745 BOOST_CHECK_EQUAL(any_cast
<int>(y2
), 4);
746 any
<dst_concept
, _a
> y3(x
, as_const(s_table
));
747 BOOST_CHECK_EQUAL(any_cast
<int>(y3
), 4);
748 any
<dst_concept
, _a
> z1(x
, table
);
749 BOOST_CHECK_EQUAL(any_cast
<int>(z1
), 4);
750 any
<dst_concept
, _a
> z2(x
, as_rvalue(table
));
751 BOOST_CHECK_EQUAL(any_cast
<int>(z2
), 4);
752 any
<dst_concept
, _a
> z3(x
, as_const(table
));
753 BOOST_CHECK_EQUAL(any_cast
<int>(z3
), 4);
756 any
<dst_concept
, _a
> ry1(as_rvalue(x
), s_table
);
757 BOOST_CHECK_EQUAL(any_cast
<int>(ry1
), 4);
758 any
<dst_concept
, _a
> ry2(as_rvalue(x
), as_rvalue(s_table
));
759 BOOST_CHECK_EQUAL(any_cast
<int>(ry2
), 4);
760 any
<dst_concept
, _a
> ry3(as_rvalue(x
), as_const(s_table
));
761 BOOST_CHECK_EQUAL(any_cast
<int>(ry3
), 4);
762 any
<dst_concept
, _a
> rz1(as_rvalue(x
), table
);
763 BOOST_CHECK_EQUAL(any_cast
<int>(rz1
), 4);
764 any
<dst_concept
, _a
> rz2(as_rvalue(x
), as_rvalue(table
));
765 BOOST_CHECK_EQUAL(any_cast
<int>(rz2
), 4);
766 any
<dst_concept
, _a
> rz3(as_rvalue(x
), as_rvalue(table
));
767 BOOST_CHECK_EQUAL(any_cast
<int>(rz3
), 4);
770 any
<dst_concept
, _a
> cy1(as_const(x
), s_table
);
771 BOOST_CHECK_EQUAL(any_cast
<int>(cy1
), 4);
772 any
<dst_concept
, _a
> cy2(as_const(x
), as_rvalue(s_table
));
773 BOOST_CHECK_EQUAL(any_cast
<int>(cy2
), 4);
774 any
<dst_concept
, _a
> cy3(as_const(x
), as_const(s_table
));
775 BOOST_CHECK_EQUAL(any_cast
<int>(cy3
), 4);
776 any
<dst_concept
, _a
> cz1(as_const(x
), table
);
777 BOOST_CHECK_EQUAL(any_cast
<int>(cz1
), 4);
778 any
<dst_concept
, _a
> cz2(as_const(x
), as_rvalue(table
));
779 BOOST_CHECK_EQUAL(any_cast
<int>(cz2
), 4);
780 any
<dst_concept
, _a
> cz3(as_const(x
), as_rvalue(table
));
781 BOOST_CHECK_EQUAL(any_cast
<int>(cz3
), 4);
784 BOOST_AUTO_TEST_CASE(test_copy_from_ref
)
786 typedef ::boost::mpl::vector
<common
<> > test_concept
;
788 any
<test_concept
, _self
&> x(i
);
789 BOOST_CHECK_EQUAL(any_cast
<int>(x
), 4);
790 any
<test_concept
> y(x
);
791 BOOST_CHECK_EQUAL(any_cast
<int>(y
), 4);
792 any
<test_concept
> z
= as_rvalue(x
);
793 BOOST_CHECK_EQUAL(any_cast
<int>(z
), 4);
794 any
<test_concept
> w
= as_const(x
);
795 BOOST_CHECK_EQUAL(any_cast
<int>(w
), 4);
798 BOOST_AUTO_TEST_CASE(test_convert_from_ref
)
800 typedef ::boost::mpl::vector
<common
<>, incrementable
<> > src_concept
;
801 typedef ::boost::mpl::vector
<common
<> > dst_concept
;
803 any
<src_concept
, _self
&> x(i
);
804 BOOST_CHECK_EQUAL(any_cast
<int>(x
), 4);
805 any
<dst_concept
> y(x
);
806 BOOST_CHECK_EQUAL(any_cast
<int>(y
), 4);
807 any
<dst_concept
> z
= as_rvalue(x
);
808 BOOST_CHECK_EQUAL(any_cast
<int>(z
), 4);
809 any
<dst_concept
> w
= as_const(x
);
810 BOOST_CHECK_EQUAL(any_cast
<int>(w
), 4);
813 BOOST_AUTO_TEST_CASE(test_rebind_from_ref
)
815 typedef ::boost::mpl::vector
<common
<> > src_concept
;
816 typedef ::boost::mpl::vector
<common
<_a
> > dst_concept
;
818 any
<src_concept
, _self
&> x(i
);
819 BOOST_CHECK_EQUAL(any_cast
<int>(x
), 4);
820 any
<dst_concept
, _a
> y(x
);
821 BOOST_CHECK_EQUAL(any_cast
<int>(y
), 4);
822 any
<dst_concept
, _a
> z
= as_rvalue(x
);
823 BOOST_CHECK_EQUAL(any_cast
<int>(z
), 4);
824 any
<dst_concept
, _a
> w
= as_const(x
);
825 BOOST_CHECK_EQUAL(any_cast
<int>(w
), 4);
828 BOOST_AUTO_TEST_CASE(test_rebind_and_convert_from_ref
)
830 typedef ::boost::mpl::vector
<common
<>, incrementable
<> > src_concept
;
831 typedef ::boost::mpl::vector
<common
<_a
> > dst_concept
;
833 any
<src_concept
, _self
&> x(i
);
834 BOOST_CHECK_EQUAL(any_cast
<int>(x
), 4);
835 any
<dst_concept
, _a
> y(x
);
836 BOOST_CHECK_EQUAL(any_cast
<int>(y
), 4);
837 any
<dst_concept
, _a
> z
= as_rvalue(x
);
838 BOOST_CHECK_EQUAL(any_cast
<int>(z
), 4);
839 any
<dst_concept
, _a
> w
= as_const(x
);
840 BOOST_CHECK_EQUAL(any_cast
<int>(w
), 4);
843 BOOST_AUTO_TEST_CASE(test_rebind_and_convert_with_binding_from_ref
)
845 typedef ::boost::mpl::vector
<common
<>, incrementable
<> > src_concept
;
846 typedef ::boost::mpl::vector
<common
<_a
> > dst_concept
;
847 typedef ::boost::mpl::map
<boost::mpl::pair
<_a
, _self
> > map
;
848 typedef ::boost::mpl::map
<boost::mpl::pair
<_a
, int> > types
;
850 static_binding
<map
> s_table(make_binding
<map
>());
851 binding
<dst_concept
> table(make_binding
<types
>());
854 any
<src_concept
, _self
&> x(i
);
855 BOOST_CHECK_EQUAL(any_cast
<int>(x
), 4);
858 any
<dst_concept
, _a
> y1(x
, s_table
);
859 BOOST_CHECK_EQUAL(any_cast
<int>(y1
), 4);
860 any
<dst_concept
, _a
> y2(x
, as_rvalue(s_table
));
861 BOOST_CHECK_EQUAL(any_cast
<int>(y2
), 4);
862 any
<dst_concept
, _a
> y3(x
, as_const(s_table
));
863 BOOST_CHECK_EQUAL(any_cast
<int>(y3
), 4);
864 any
<dst_concept
, _a
> z1(x
, table
);
865 BOOST_CHECK_EQUAL(any_cast
<int>(z1
), 4);
866 any
<dst_concept
, _a
> z2(x
, as_rvalue(table
));
867 BOOST_CHECK_EQUAL(any_cast
<int>(z2
), 4);
868 any
<dst_concept
, _a
> z3(x
, as_const(table
));
869 BOOST_CHECK_EQUAL(any_cast
<int>(z3
), 4);
872 any
<dst_concept
, _a
> ry1(as_rvalue(x
), s_table
);
873 BOOST_CHECK_EQUAL(any_cast
<int>(ry1
), 4);
874 any
<dst_concept
, _a
> ry2(as_rvalue(x
), as_rvalue(s_table
));
875 BOOST_CHECK_EQUAL(any_cast
<int>(ry2
), 4);
876 any
<dst_concept
, _a
> ry3(as_rvalue(x
), as_const(s_table
));
877 BOOST_CHECK_EQUAL(any_cast
<int>(ry3
), 4);
878 any
<dst_concept
, _a
> rz1(as_rvalue(x
), table
);
879 BOOST_CHECK_EQUAL(any_cast
<int>(rz1
), 4);
880 any
<dst_concept
, _a
> rz2(as_rvalue(x
), as_rvalue(table
));
881 BOOST_CHECK_EQUAL(any_cast
<int>(rz2
), 4);
882 any
<dst_concept
, _a
> rz3(as_rvalue(x
), as_rvalue(table
));
883 BOOST_CHECK_EQUAL(any_cast
<int>(rz3
), 4);
886 any
<dst_concept
, _a
> cy1(as_const(x
), s_table
);
887 BOOST_CHECK_EQUAL(any_cast
<int>(cy1
), 4);
888 any
<dst_concept
, _a
> cy2(as_const(x
), as_rvalue(s_table
));
889 BOOST_CHECK_EQUAL(any_cast
<int>(cy2
), 4);
890 any
<dst_concept
, _a
> cy3(as_const(x
), as_const(s_table
));
891 BOOST_CHECK_EQUAL(any_cast
<int>(cy3
), 4);
892 any
<dst_concept
, _a
> cz1(as_const(x
), table
);
893 BOOST_CHECK_EQUAL(any_cast
<int>(cz1
), 4);
894 any
<dst_concept
, _a
> cz2(as_const(x
), as_rvalue(table
));
895 BOOST_CHECK_EQUAL(any_cast
<int>(cz2
), 4);
896 any
<dst_concept
, _a
> cz3(as_const(x
), as_rvalue(table
));
897 BOOST_CHECK_EQUAL(any_cast
<int>(cz3
), 4);
900 BOOST_AUTO_TEST_CASE(test_copy_from_cref
)
902 typedef ::boost::mpl::vector
<common
<> > test_concept
;
904 any
<test_concept
, const _self
&> x(i
);
905 BOOST_CHECK_EQUAL(any_cast
<int>(x
), 4);
906 any
<test_concept
> y(x
);
907 BOOST_CHECK_EQUAL(any_cast
<int>(y
), 4);
908 any
<test_concept
> z
= as_rvalue(x
);
909 BOOST_CHECK_EQUAL(any_cast
<int>(z
), 4);
910 any
<test_concept
> w
= as_const(x
);
911 BOOST_CHECK_EQUAL(any_cast
<int>(w
), 4);
914 BOOST_AUTO_TEST_CASE(test_convert_from_cref
)
916 typedef ::boost::mpl::vector
<common
<>, incrementable
<> > src_concept
;
917 typedef ::boost::mpl::vector
<common
<> > dst_concept
;
919 any
<src_concept
, const _self
&> x(i
);
920 BOOST_CHECK_EQUAL(any_cast
<int>(x
), 4);
921 any
<dst_concept
> y(x
);
922 BOOST_CHECK_EQUAL(any_cast
<int>(y
), 4);
923 any
<dst_concept
> z
= as_rvalue(x
);
924 BOOST_CHECK_EQUAL(any_cast
<int>(z
), 4);
925 any
<dst_concept
> w
= as_const(x
);
926 BOOST_CHECK_EQUAL(any_cast
<int>(w
), 4);
929 BOOST_AUTO_TEST_CASE(test_rebind_from_cref
)
931 typedef ::boost::mpl::vector
<common
<> > src_concept
;
932 typedef ::boost::mpl::vector
<common
<_a
> > dst_concept
;
934 any
<src_concept
, const _self
&> x(i
);
935 BOOST_CHECK_EQUAL(any_cast
<int>(x
), 4);
936 any
<dst_concept
, _a
> y(x
);
937 BOOST_CHECK_EQUAL(any_cast
<int>(y
), 4);
938 any
<dst_concept
, _a
> z
= as_rvalue(x
);
939 BOOST_CHECK_EQUAL(any_cast
<int>(z
), 4);
940 any
<dst_concept
, _a
> w
= as_const(x
);
941 BOOST_CHECK_EQUAL(any_cast
<int>(w
), 4);
944 BOOST_AUTO_TEST_CASE(test_rebind_and_convert_from_cref
)
946 typedef ::boost::mpl::vector
<common
<>, incrementable
<> > src_concept
;
947 typedef ::boost::mpl::vector
<common
<_a
> > dst_concept
;
949 any
<src_concept
, const _self
&> x(i
);
950 BOOST_CHECK_EQUAL(any_cast
<int>(x
), 4);
951 any
<dst_concept
, _a
> y(x
);
952 BOOST_CHECK_EQUAL(any_cast
<int>(y
), 4);
953 any
<dst_concept
, _a
> z
= as_rvalue(x
);
954 BOOST_CHECK_EQUAL(any_cast
<int>(z
), 4);
955 any
<dst_concept
, _a
> w
= as_const(x
);
956 BOOST_CHECK_EQUAL(any_cast
<int>(w
), 4);
959 BOOST_AUTO_TEST_CASE(test_rebind_and_convert_with_binding_from_cref
)
961 typedef ::boost::mpl::vector
<common
<>, incrementable
<> > src_concept
;
962 typedef ::boost::mpl::vector
<common
<_a
> > dst_concept
;
963 typedef ::boost::mpl::map
<boost::mpl::pair
<_a
, _self
> > map
;
964 typedef ::boost::mpl::map
<boost::mpl::pair
<_a
, int> > types
;
966 static_binding
<map
> s_table(make_binding
<map
>());
967 binding
<dst_concept
> table(make_binding
<types
>());
970 any
<src_concept
, const _self
&> x(i
);
971 BOOST_CHECK_EQUAL(any_cast
<int>(x
), 4);
974 any
<dst_concept
, _a
> y1(x
, s_table
);
975 BOOST_CHECK_EQUAL(any_cast
<int>(y1
), 4);
976 any
<dst_concept
, _a
> y2(x
, as_rvalue(s_table
));
977 BOOST_CHECK_EQUAL(any_cast
<int>(y2
), 4);
978 any
<dst_concept
, _a
> y3(x
, as_const(s_table
));
979 BOOST_CHECK_EQUAL(any_cast
<int>(y3
), 4);
980 any
<dst_concept
, _a
> z1(x
, table
);
981 BOOST_CHECK_EQUAL(any_cast
<int>(z1
), 4);
982 any
<dst_concept
, _a
> z2(x
, as_rvalue(table
));
983 BOOST_CHECK_EQUAL(any_cast
<int>(z2
), 4);
984 any
<dst_concept
, _a
> z3(x
, as_const(table
));
985 BOOST_CHECK_EQUAL(any_cast
<int>(z3
), 4);
988 any
<dst_concept
, _a
> ry1(as_rvalue(x
), s_table
);
989 BOOST_CHECK_EQUAL(any_cast
<int>(ry1
), 4);
990 any
<dst_concept
, _a
> ry2(as_rvalue(x
), as_rvalue(s_table
));
991 BOOST_CHECK_EQUAL(any_cast
<int>(ry2
), 4);
992 any
<dst_concept
, _a
> ry3(as_rvalue(x
), as_const(s_table
));
993 BOOST_CHECK_EQUAL(any_cast
<int>(ry3
), 4);
994 any
<dst_concept
, _a
> rz1(as_rvalue(x
), table
);
995 BOOST_CHECK_EQUAL(any_cast
<int>(rz1
), 4);
996 any
<dst_concept
, _a
> rz2(as_rvalue(x
), as_rvalue(table
));
997 BOOST_CHECK_EQUAL(any_cast
<int>(rz2
), 4);
998 any
<dst_concept
, _a
> rz3(as_rvalue(x
), as_rvalue(table
));
999 BOOST_CHECK_EQUAL(any_cast
<int>(rz3
), 4);
1002 any
<dst_concept
, _a
> cy1(as_const(x
), s_table
);
1003 BOOST_CHECK_EQUAL(any_cast
<int>(cy1
), 4);
1004 any
<dst_concept
, _a
> cy2(as_const(x
), as_rvalue(s_table
));
1005 BOOST_CHECK_EQUAL(any_cast
<int>(cy2
), 4);
1006 any
<dst_concept
, _a
> cy3(as_const(x
), as_const(s_table
));
1007 BOOST_CHECK_EQUAL(any_cast
<int>(cy3
), 4);
1008 any
<dst_concept
, _a
> cz1(as_const(x
), table
);
1009 BOOST_CHECK_EQUAL(any_cast
<int>(cz1
), 4);
1010 any
<dst_concept
, _a
> cz2(as_const(x
), as_rvalue(table
));
1011 BOOST_CHECK_EQUAL(any_cast
<int>(cz2
), 4);
1012 any
<dst_concept
, _a
> cz3(as_const(x
), as_rvalue(table
));
1013 BOOST_CHECK_EQUAL(any_cast
<int>(cz3
), 4);
1016 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
1020 explicit move_only(int i
) : value(i
) {}
1021 move_only(move_only
&& other
) : value(other
.value
) { other
.value
= 0; }
1024 move_only(const move_only
&);
1027 BOOST_AUTO_TEST_CASE(test_move_only
)
1029 typedef ::boost::mpl::vector
<destructible
<>, typeid_
<> > test_concept
;
1030 move_only
source(2);
1031 any
<test_concept
> x(std::move(source
));
1032 BOOST_CHECK_EQUAL(source
.value
, 0);
1033 BOOST_CHECK_EQUAL(any_cast
<move_only
&>(x
).value
, 2);
1036 BOOST_AUTO_TEST_CASE(test_copy_from_rref
)
1038 typedef ::boost::mpl::vector
<common
<> > test_concept
;
1040 any
<test_concept
, _self
&&> x(std::move(i
));
1041 BOOST_CHECK_EQUAL(any_cast
<int>(x
), 4);
1042 any
<test_concept
> y(x
);
1043 BOOST_CHECK_EQUAL(any_cast
<int>(y
), 4);
1044 any
<test_concept
> z
= as_rvalue(x
);
1045 BOOST_CHECK_EQUAL(any_cast
<int>(z
), 4);
1046 any
<test_concept
> w
= as_const(x
);
1047 BOOST_CHECK_EQUAL(any_cast
<int>(w
), 4);
1050 BOOST_AUTO_TEST_CASE(test_convert_from_rref
)
1052 typedef ::boost::mpl::vector
<common
<>, incrementable
<> > src_concept
;
1053 typedef ::boost::mpl::vector
<common
<> > dst_concept
;
1055 any
<src_concept
, _self
&&> x(std::move(i
));
1056 BOOST_CHECK_EQUAL(any_cast
<int>(x
), 4);
1057 any
<dst_concept
> y(x
);
1058 BOOST_CHECK_EQUAL(any_cast
<int>(y
), 4);
1059 any
<dst_concept
> z
= as_rvalue(x
);
1060 BOOST_CHECK_EQUAL(any_cast
<int>(z
), 4);
1061 any
<dst_concept
> w
= as_const(x
);
1062 BOOST_CHECK_EQUAL(any_cast
<int>(w
), 4);
1065 BOOST_AUTO_TEST_CASE(test_rebind_from_rref
)
1067 typedef ::boost::mpl::vector
<common
<> > src_concept
;
1068 typedef ::boost::mpl::vector
<common
<_a
> > dst_concept
;
1070 any
<src_concept
, _self
&&> x(std::move(i
));
1071 BOOST_CHECK_EQUAL(any_cast
<int>(x
), 4);
1072 any
<dst_concept
, _a
> y(x
);
1073 BOOST_CHECK_EQUAL(any_cast
<int>(y
), 4);
1074 any
<dst_concept
, _a
> z
= as_rvalue(x
);
1075 BOOST_CHECK_EQUAL(any_cast
<int>(z
), 4);
1076 any
<dst_concept
, _a
> w
= as_const(x
);
1077 BOOST_CHECK_EQUAL(any_cast
<int>(w
), 4);
1080 BOOST_AUTO_TEST_CASE(test_rebind_and_convert_from_rref
)
1082 typedef ::boost::mpl::vector
<common
<>, incrementable
<> > src_concept
;
1083 typedef ::boost::mpl::vector
<common
<_a
> > dst_concept
;
1085 any
<src_concept
, _self
&&> x(std::move(i
));
1086 BOOST_CHECK_EQUAL(any_cast
<int>(x
), 4);
1087 any
<dst_concept
, _a
> y(x
);
1088 BOOST_CHECK_EQUAL(any_cast
<int>(y
), 4);
1089 any
<dst_concept
, _a
> z
= as_rvalue(x
);
1090 BOOST_CHECK_EQUAL(any_cast
<int>(z
), 4);
1091 any
<dst_concept
, _a
> w
= as_const(x
);
1092 BOOST_CHECK_EQUAL(any_cast
<int>(w
), 4);
1095 BOOST_AUTO_TEST_CASE(test_rebind_and_convert_with_binding_from_rref
)
1097 typedef ::boost::mpl::vector
<common
<>, incrementable
<> > src_concept
;
1098 typedef ::boost::mpl::vector
<common
<_a
> > dst_concept
;
1099 typedef ::boost::mpl::map
<boost::mpl::pair
<_a
, _self
> > map
;
1100 typedef ::boost::mpl::map
<boost::mpl::pair
<_a
, int> > types
;
1102 static_binding
<map
> s_table(make_binding
<map
>());
1103 binding
<dst_concept
> table(make_binding
<types
>());
1106 any
<src_concept
, _self
&&> x(std::move(i
));
1107 BOOST_CHECK_EQUAL(any_cast
<int>(x
), 4);
1110 any
<dst_concept
, _a
> y1(x
, s_table
);
1111 BOOST_CHECK_EQUAL(any_cast
<int>(y1
), 4);
1112 any
<dst_concept
, _a
> y2(x
, as_rvalue(s_table
));
1113 BOOST_CHECK_EQUAL(any_cast
<int>(y2
), 4);
1114 any
<dst_concept
, _a
> y3(x
, as_const(s_table
));
1115 BOOST_CHECK_EQUAL(any_cast
<int>(y3
), 4);
1116 any
<dst_concept
, _a
> z1(x
, table
);
1117 BOOST_CHECK_EQUAL(any_cast
<int>(z1
), 4);
1118 any
<dst_concept
, _a
> z2(x
, as_rvalue(table
));
1119 BOOST_CHECK_EQUAL(any_cast
<int>(z2
), 4);
1120 any
<dst_concept
, _a
> z3(x
, as_const(table
));
1121 BOOST_CHECK_EQUAL(any_cast
<int>(z3
), 4);
1124 any
<dst_concept
, _a
> ry1(as_rvalue(x
), s_table
);
1125 BOOST_CHECK_EQUAL(any_cast
<int>(ry1
), 4);
1126 any
<dst_concept
, _a
> ry2(as_rvalue(x
), as_rvalue(s_table
));
1127 BOOST_CHECK_EQUAL(any_cast
<int>(ry2
), 4);
1128 any
<dst_concept
, _a
> ry3(as_rvalue(x
), as_const(s_table
));
1129 BOOST_CHECK_EQUAL(any_cast
<int>(ry3
), 4);
1130 any
<dst_concept
, _a
> rz1(as_rvalue(x
), table
);
1131 BOOST_CHECK_EQUAL(any_cast
<int>(rz1
), 4);
1132 any
<dst_concept
, _a
> rz2(as_rvalue(x
), as_rvalue(table
));
1133 BOOST_CHECK_EQUAL(any_cast
<int>(rz2
), 4);
1134 any
<dst_concept
, _a
> rz3(as_rvalue(x
), as_rvalue(table
));
1135 BOOST_CHECK_EQUAL(any_cast
<int>(rz3
), 4);
1138 any
<dst_concept
, _a
> cy1(as_const(x
), s_table
);
1139 BOOST_CHECK_EQUAL(any_cast
<int>(cy1
), 4);
1140 any
<dst_concept
, _a
> cy2(as_const(x
), as_rvalue(s_table
));
1141 BOOST_CHECK_EQUAL(any_cast
<int>(cy2
), 4);
1142 any
<dst_concept
, _a
> cy3(as_const(x
), as_const(s_table
));
1143 BOOST_CHECK_EQUAL(any_cast
<int>(cy3
), 4);
1144 any
<dst_concept
, _a
> cz1(as_const(x
), table
);
1145 BOOST_CHECK_EQUAL(any_cast
<int>(cz1
), 4);
1146 any
<dst_concept
, _a
> cz2(as_const(x
), as_rvalue(table
));
1147 BOOST_CHECK_EQUAL(any_cast
<int>(cz2
), 4);
1148 any
<dst_concept
, _a
> cz3(as_const(x
), as_rvalue(table
));
1149 BOOST_CHECK_EQUAL(any_cast
<int>(cz3
), 4);