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/mpl/vector.hpp> |
17 | |
18 | #define BOOST_TEST_MAIN |
19 | #include <boost/test/unit_test.hpp> |
20 | |
21 | using namespace boost::type_erasure; |
22 | |
23 | template<class T = _self> |
24 | struct common : ::boost::mpl::vector< |
25 | destructible<T>, |
26 | copy_constructible<T>, |
27 | typeid_<T> |
28 | > {}; |
29 | |
30 | BOOST_AUTO_TEST_CASE(test_value) |
31 | { |
32 | typedef ::boost::mpl::vector<common<>, incrementable<> > test_concept; |
33 | any<test_concept> x(1); |
34 | ++x; |
35 | BOOST_CHECK_EQUAL(any_cast<int>(x), 2); |
36 | any<test_concept> y(x++); |
37 | BOOST_CHECK_EQUAL(any_cast<int>(x), 3); |
38 | BOOST_CHECK_EQUAL(any_cast<int>(y), 2); |
39 | } |
40 | |
41 | BOOST_AUTO_TEST_CASE(test_reference) |
42 | { |
43 | typedef ::boost::mpl::vector<common<>, incrementable<> > test_concept; |
44 | int i = 1; |
45 | any<test_concept, _self&> x(i); |
46 | ++x; |
47 | BOOST_CHECK_EQUAL(i, 2); |
48 | any<test_concept> y(x++); |
49 | BOOST_CHECK_EQUAL(i, 3); |
50 | BOOST_CHECK_EQUAL(any_cast<int>(y), 2); |
51 | } |
52 | |