1 // Boost.TypeErasure library
3 // Copyright 2012 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/free.hpp>
14 #include <boost/mpl/vector.hpp>
16 #define BOOST_TEST_MAIN
17 #include <boost/test/unit_test.hpp>
19 using namespace boost::type_erasure
;
22 explicit model(int v
) : val(v
) {}
26 int f1(model
& m
) { return m
.val
; }
27 int f1(model
& m
, int i
) { return m
.val
+ i
; }
29 BOOST_TYPE_ERASURE_FREE((global_has_f1_1
), f1
, 1);
31 BOOST_AUTO_TEST_CASE(test_global_has_f1_1
) {
32 typedef ::boost::mpl::vector
<
33 global_has_f1_1
<int(_self
&)>,
34 copy_constructible
<> > concept_type
;
36 any
<concept_type
> x(m
);
37 BOOST_CHECK_EQUAL(f1(x
), 10);
40 BOOST_TYPE_ERASURE_FREE((ns1
)(ns2
)(ns_has_f1_1
), f1
, 1);
42 BOOST_AUTO_TEST_CASE(test_ns_has_f1_1
) {
43 typedef ::boost::mpl::vector
<
44 ns1::ns2::ns_has_f1_1
<int(_self
&)>,
45 copy_constructible
<> > concept_type
;
47 any
<concept_type
> x(m
);
48 BOOST_CHECK_EQUAL(f1(x
), 10);
52 explicit model_const(int v
) : val(v
) {}
56 int f1(const model_const
& m
) { return m
.val
; }
57 int f1(const model_const
& m
, int i
) { return m
.val
+ i
; }
59 BOOST_AUTO_TEST_CASE(test_global_has_f1_1_const
) {
60 typedef ::boost::mpl::vector
<
61 ns1::ns2::ns_has_f1_1
<int(const _self
&)>,
62 copy_constructible
<> > concept_type
;
64 const any
<concept_type
> x(m
);
65 BOOST_CHECK_EQUAL(f1(x
), 10);
68 BOOST_AUTO_TEST_CASE(test_global_has_f1_1_void
) {
69 typedef ::boost::mpl::vector
<
70 global_has_f1_1
<void(_self
&)>,
71 copy_constructible
<> > concept_type
;
73 any
<concept_type
> x(m
);
77 BOOST_TYPE_ERASURE_FREE((global_has_f1_2
), f1
, 2);
79 BOOST_AUTO_TEST_CASE(test_global_has_f1_overload
) {
80 typedef ::boost::mpl::vector
<
81 global_has_f1_1
<int(_self
&)>,
82 global_has_f1_2
<int(_self
&, int)>,
83 copy_constructible
<> > concept_type
;
85 any
<concept_type
> x(m
);
86 BOOST_CHECK_EQUAL(f1(x
), 10);
87 BOOST_CHECK_EQUAL(f1(x
, 5), 15);
90 BOOST_AUTO_TEST_CASE(test_global_has_f1_overload_const
) {
91 typedef ::boost::mpl::vector
<
92 global_has_f1_1
<int(const _self
&)>,
93 global_has_f1_2
<int(const _self
&, int)>,
94 copy_constructible
<> > concept_type
;
96 const any
<concept_type
> x(m
);
97 BOOST_CHECK_EQUAL(f1(x
), 10);
98 BOOST_CHECK_EQUAL(f1(x
, 5), 15);
101 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
103 BOOST_AUTO_TEST_CASE(test_global_has_f1_rv
) {
104 typedef ::boost::mpl::vector
<
105 global_has_f1_2
<int(_self
&&, int&&)>,
106 copy_constructible
<> > concept_type
;
108 any
<concept_type
> x(m
);
109 BOOST_CHECK_EQUAL(f1(std::move(x
), 5), 15);