]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/type_erasure/test/test_dereference.cpp
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/builtin.hpp>
13 #include <boost/type_erasure/operators.hpp>
14 #include <boost/type_erasure/any_cast.hpp>
15 #include <boost/mpl/vector.hpp>
17 #define BOOST_TEST_MAIN
18 #include <boost/test/unit_test.hpp>
20 using namespace boost::type_erasure
;
22 template<class T
= _self
>
23 struct common
: ::boost::mpl::vector
<
24 copy_constructible
<T
>,
28 BOOST_AUTO_TEST_CASE(test_basic
)
30 typedef ::boost::mpl::vector
<common
<>, dereferenceable
<int&> > test_concept
;
32 any
<test_concept
> x(&i
);
33 BOOST_CHECK_EQUAL(&*x
, &i
);
36 BOOST_AUTO_TEST_CASE(test_any_result
)
38 typedef ::boost::mpl::vector
<common
<>, common
<_a
>, dereferenceable
<_a
&> > test_concept
;
39 typedef ::boost::mpl::map
<
40 ::boost::mpl::pair
<_self
, int*>,
41 ::boost::mpl::pair
<_a
, int>
44 any
<test_concept
> x(&i
, make_binding
<types
>());
45 any
<test_concept
, _a
&> y(*x
);
46 BOOST_CHECK_EQUAL(any_cast
<int*>(&y
), &i
);
49 BOOST_AUTO_TEST_CASE(test_any_result_const
)
51 typedef ::boost::mpl::vector
<common
<>, common
<_a
>, dereferenceable
<const _a
&> > test_concept
;
52 typedef ::boost::mpl::map
<
53 ::boost::mpl::pair
<_self
, const int*>,
54 ::boost::mpl::pair
<_a
, int>
57 any
<test_concept
> x(&i
, make_binding
<types
>());
58 any
<test_concept
, const _a
&> y(*x
);
59 BOOST_CHECK_EQUAL(any_cast
<const int*>(&y
), &i
);