1 | // Boost.TypeErasure library |
---|---|
2 | // |
3 | // Copyright 2011 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/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/typeid_of.hpp> |
17 | #include <boost/mpl/vector.hpp> |
18 | |
19 | #define BOOST_TEST_MAIN |
20 | #include <boost/test/unit_test.hpp> |
21 | |
22 | using namespace boost::type_erasure; |
23 | |
24 | template<class T = _self> |
25 | struct common : ::boost::mpl::vector< |
26 | copy_constructible<T>, |
27 | typeid_<T> |
28 | > {}; |
29 | |
30 | BOOST_AUTO_TEST_CASE(test_val) |
31 | { |
32 | typedef common<> test_concept; |
33 | any<test_concept> x(2); |
34 | BOOST_CHECK(typeid_of(x) == typeid(int)); |
35 | const any<test_concept> y(2); |
36 | BOOST_CHECK(typeid_of(y) == typeid(int)); |
37 | } |
38 | |
39 | BOOST_AUTO_TEST_CASE(test_ref) |
40 | { |
41 | typedef common<> test_concept; |
42 | int i; |
43 | any<test_concept, _self&> x(i); |
44 | BOOST_CHECK(typeid_of(x) == typeid(int)); |
45 | const any<test_concept, _self&> y(i); |
46 | BOOST_CHECK(typeid_of(y) == typeid(int)); |
47 | } |
48 | |
49 | BOOST_AUTO_TEST_CASE(test_cref) |
50 | { |
51 | typedef common<> test_concept; |
52 | int i; |
53 | any<test_concept, const _self&> x(i); |
54 | BOOST_CHECK(typeid_of(x) == typeid(int)); |
55 | const any<test_concept, const _self&> y(i); |
56 | BOOST_CHECK(typeid_of(y) == typeid(int)); |
57 | } |
58 | |
59 | BOOST_AUTO_TEST_CASE(test_binding) |
60 | { |
61 | typedef boost::mpl::vector<common<_a>, common<_b> > test_concept; |
62 | binding<test_concept> b = |
63 | make_binding< |
64 | boost::mpl::map< |
65 | boost::mpl::pair<_a, int>, |
66 | boost::mpl::pair<_b, double> |
67 | > |
68 | >(); |
69 | BOOST_CHECK(typeid_of<_a>(b) == typeid(int)); |
70 | BOOST_CHECK(typeid_of<_b>(b) == typeid(double)); |
71 | } |
72 |