]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/type_erasure/test/test_add_assign.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/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>
18 #define BOOST_TEST_MAIN
19 #include <boost/test/unit_test.hpp>
21 using namespace boost::type_erasure
;
23 template<class T
= _self
>
24 struct common
: ::boost::mpl::vector
<
26 copy_constructible
<T
>,
30 BOOST_AUTO_TEST_CASE(test_same
)
32 typedef ::boost::mpl::vector
<common
<>, add_assignable
<> > test_concept
;
33 any
<test_concept
> x(1);
34 any
<test_concept
> y(2);
35 any
<test_concept
>& z(x
+= y
);
36 BOOST_CHECK_EQUAL(any_cast
<int>(x
), 3);
37 BOOST_CHECK_EQUAL(&x
, &z
);
40 BOOST_AUTO_TEST_CASE(test_int1
)
42 typedef ::boost::mpl::vector
<common
<>, add_assignable
<_self
, int> > test_concept
;
43 any
<test_concept
> x(1);
44 any
<test_concept
>& z(x
+= 2);
45 BOOST_CHECK_EQUAL(any_cast
<int>(x
), 3);
46 BOOST_CHECK_EQUAL(&x
, &z
);
49 BOOST_AUTO_TEST_CASE(test_int2
)
51 typedef ::boost::mpl::vector
<common
<>, add_assignable
<int, _self
> > test_concept
;
53 any
<test_concept
> y(2);
55 BOOST_CHECK_EQUAL(x
, 3);
56 BOOST_CHECK_EQUAL(&x
, &z
);
59 BOOST_AUTO_TEST_CASE(test_mixed
)
61 typedef ::boost::mpl::vector
<common
<_a
>, common
<_b
>, add_assignable
<_a
, _b
> > test_concept
;
62 tuple
<test_concept
, _a
, _b
> t(1.0, 2);
63 any
<test_concept
, _a
> x(get
<0>(t
));
64 any
<test_concept
, _b
> y(get
<1>(t
));
65 any
<test_concept
, _a
>& z(x
+= y
);
66 BOOST_CHECK_EQUAL(any_cast
<double>(x
), 3.0);
67 BOOST_CHECK_EQUAL(&x
, &z
);
70 BOOST_AUTO_TEST_CASE(test_overload
)
72 typedef ::boost::mpl::vector
<
76 add_assignable
<_a
, int>,
77 add_assignable
<double, _a
>,
79 add_assignable
<_b
, int>,
80 add_assignable
<double, _b
>,
81 add_assignable
<_a
, _b
>
83 tuple
<test_concept
, _a
, _b
> t(1.0, 2);
86 any
<test_concept
, _a
> x(get
<0>(t
));
87 any
<test_concept
, _a
> y(get
<0>(t
));
88 any
<test_concept
, _a
>& z(x
+= y
);
89 BOOST_CHECK_EQUAL(any_cast
<double>(x
), 2.0);
90 BOOST_CHECK_EQUAL(&x
, &z
);
94 any
<test_concept
, _a
> x(get
<0>(t
));
96 any
<test_concept
, _a
>& z(x
+= y
);
97 BOOST_CHECK_EQUAL(any_cast
<double>(x
), 6.0);
98 BOOST_CHECK_EQUAL(&x
, &z
);
103 any
<test_concept
, _a
> y(get
<0>(t
));
105 BOOST_CHECK_EQUAL(x
, 12);
106 BOOST_CHECK_EQUAL(&x
, &z
);
110 any
<test_concept
, _b
> x(get
<1>(t
));
111 any
<test_concept
, _b
> y(get
<1>(t
));
112 any
<test_concept
, _b
>& z(x
+= y
);
113 BOOST_CHECK_EQUAL(any_cast
<int>(x
), 4);
114 BOOST_CHECK_EQUAL(&x
, &z
);
118 any
<test_concept
, _b
> x(get
<1>(t
));
120 any
<test_concept
, _b
>& z(x
+= y
);
121 BOOST_CHECK_EQUAL(any_cast
<int>(x
), 7);
122 BOOST_CHECK_EQUAL(&x
, &z
);
127 any
<test_concept
, _b
> y(get
<1>(t
));
129 BOOST_CHECK_EQUAL(x
, 13);
130 BOOST_CHECK_EQUAL(&x
, &z
);
134 any
<test_concept
, _a
> x(get
<0>(t
));
135 any
<test_concept
, _b
> y(get
<1>(t
));
136 any
<test_concept
, _a
>& z(x
+= y
);
137 BOOST_CHECK_EQUAL(any_cast
<double>(x
), 3.0);
138 BOOST_CHECK_EQUAL(&x
, &z
);