1 | // Boost.TypeErasure library |
2 | // |
3 | // Copyright 2012 Steven Watanabe |
4 | // |
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) |
8 | // |
9 | // $Id$ |
10 | |
11 | #include <boost/type_erasure/any.hpp> |
12 | #include <boost/type_erasure/builtin.hpp> |
13 | #include <boost/type_erasure/operators.hpp> |
14 | #include <boost/type_erasure/any_cast.hpp> |
15 | #include <boost/type_erasure/deduced.hpp> |
16 | #include <boost/type_erasure/same_type.hpp> |
17 | #include <boost/mpl/vector.hpp> |
18 | #include <boost/mpl/assert.hpp> |
19 | #include <boost/type_traits/remove_pointer.hpp> |
20 | #include <boost/type_traits/is_same.hpp> |
21 | |
22 | #define BOOST_TEST_MAIN |
23 | #include <boost/test/unit_test.hpp> |
24 | |
25 | using namespace boost::type_erasure; |
26 | |
27 | BOOST_AUTO_TEST_CASE(test_deduce_dereference) |
28 | { |
29 | typedef ::boost::mpl::vector< |
30 | copy_constructible<>, |
31 | typeid_<_a>, |
32 | dereferenceable<deduced<boost::remove_pointer<_self> >&>, |
33 | same_type<deduced<boost::remove_pointer<_self> >, _a> |
34 | > test_concept; |
35 | int i; |
36 | |
37 | any<test_concept> x(&i); |
38 | any<test_concept, _a&> y(*x); |
39 | BOOST_CHECK_EQUAL(&any_cast<int&>(y), &i); |
40 | } |
41 | |
42 | BOOST_MPL_ASSERT(( |
43 | boost::is_same< |
44 | deduced<boost::remove_pointer<_self> >::type, |
45 | deduced<boost::remove_pointer<_self> > >)); |
46 | |
47 | BOOST_MPL_ASSERT(( |
48 | boost::is_same<deduced<boost::remove_pointer<int*> >::type, int >)); |
49 | |
50 | BOOST_AUTO_TEST_CASE(test_duplicate) |
51 | { |
52 | typedef ::boost::mpl::vector< |
53 | copy_constructible<>, |
54 | typeid_<_a>, |
55 | dereferenceable<deduced<boost::remove_pointer<_self> >&>, |
56 | same_type<deduced<boost::remove_pointer<_self> >, _a>, |
57 | same_type<deduced<boost::remove_pointer<_self> >, _a> |
58 | > test_concept; |
59 | int i; |
60 | |
61 | any<test_concept> x(&i); |
62 | any<test_concept, _a&> y(*x); |
63 | BOOST_CHECK_EQUAL(&any_cast<int&>(y), &i); |
64 | } |
65 | |
66 | BOOST_AUTO_TEST_CASE(test_convert) |
67 | { |
68 | typedef ::boost::mpl::vector< |
69 | copy_constructible<>, |
70 | typeid_<_a>, |
71 | dereferenceable<deduced<boost::remove_pointer<_self> >&>, |
72 | same_type<deduced<boost::remove_pointer<_self> >, _a> |
73 | > test_concept_src; |
74 | typedef ::boost::mpl::vector< |
75 | copy_constructible<_b>, |
76 | typeid_<_c>, |
77 | dereferenceable<deduced<boost::remove_pointer<_b> >&, _b>, |
78 | same_type<deduced<boost::remove_pointer<_b> >, _c> |
79 | > test_concept_dest; |
80 | int i; |
81 | |
82 | any<test_concept_src> x1(&i); |
83 | any<test_concept_src, _a&> y1(*x1); |
84 | any<test_concept_dest, _b> x2(x1); |
85 | any<test_concept_dest, _c&> y2(*x2); |
86 | BOOST_CHECK_EQUAL(&any_cast<int&>(y2), &i); |
87 | } |
88 | |