]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/tr1/test/test_ref_wrapper_tricky.cpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / tr1 / test / test_ref_wrapper_tricky.cpp
1 // (C) Copyright John Maddock 2005.
2 // Use, modification and distribution are subject to the
3 // Boost Software License, Version 1.0. (See accompanying file
4 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5
6 #ifdef TEST_STD_HEADERS
7 #include <functional>
8 #else
9 #include <boost/tr1/functional.hpp>
10 #endif
11
12 #include <boost/static_assert.hpp>
13 #include <boost/type_traits/is_convertible.hpp>
14 #include <boost/type_traits/is_same.hpp>
15 #include <boost/type_traits/is_base_and_derived.hpp>
16 #include "verify_return.hpp"
17
18 struct test_type
19 {
20 int member();
21 int cmember()const;
22 int member2(char);
23 int cmember2(char)const;
24 };
25
26 struct functor1 : public std::unary_function<int, double>
27 {
28 double operator()(int)const;
29 };
30
31 struct functor2 : public std::binary_function<int, char, double>
32 {
33 double operator()(int, char)const;
34 };
35
36 int main()
37 {
38 BOOST_STATIC_ASSERT((::boost::is_base_and_derived<std::unary_function<int, double>, std::tr1::reference_wrapper<double (int)> >::value));
39 BOOST_STATIC_ASSERT((::boost::is_base_and_derived<std::unary_function<int, double>, std::tr1::reference_wrapper<double (*)(int)> >::value));
40 BOOST_STATIC_ASSERT((::boost::is_base_and_derived<std::unary_function<test_type*, int>, std::tr1::reference_wrapper<int (test_type::*)()> >::value));
41 BOOST_STATIC_ASSERT((::boost::is_base_and_derived<std::unary_function<const test_type*, int>, std::tr1::reference_wrapper<int (test_type::*)()const> >::value));
42 BOOST_STATIC_ASSERT((::boost::is_base_and_derived<std::unary_function<int, double>, std::tr1::reference_wrapper<functor1> >::value));
43
44 BOOST_STATIC_ASSERT((::boost::is_base_and_derived<std::binary_function<int, char, double>, std::tr1::reference_wrapper<double (int, char)> >::value));
45 BOOST_STATIC_ASSERT((::boost::is_base_and_derived<std::binary_function<int, char, double>, std::tr1::reference_wrapper<double (*)(int, char)> >::value));
46 BOOST_STATIC_ASSERT((::boost::is_base_and_derived<std::binary_function<test_type*, char, int>, std::tr1::reference_wrapper<int (test_type::*)(char)> >::value));
47 BOOST_STATIC_ASSERT((::boost::is_base_and_derived<std::binary_function<const test_type*, char, int>, std::tr1::reference_wrapper<int (test_type::*)(char)const> >::value));
48 BOOST_STATIC_ASSERT((::boost::is_base_and_derived<std::binary_function<int, char, double>, std::tr1::reference_wrapper<functor2> >::value));
49
50 test_type* ptt = 0;
51 test_type const* cptt = 0;
52 int zero = 0;
53
54 // now check operator():
55 std::tr1::reference_wrapper<double (int)>* pr1;
56 verify_return_type((*pr1)(0), double());
57 std::tr1::reference_wrapper<double (*)(int)>* pr2;
58 verify_return_type((*pr2)(0), double());
59 std::tr1::reference_wrapper<int (test_type::*)()>* pr3;
60 verify_return_type((*pr3)(ptt), int());
61 std::tr1::reference_wrapper<int (test_type::*)()const>* pr4;
62 verify_return_type((*pr4)(cptt), int());
63 std::tr1::reference_wrapper<functor1>* pr5;
64 verify_return_type((*pr5)(zero), double());
65
66 std::tr1::reference_wrapper<double (int, char)>* pr1b;
67 verify_return_type((*pr1b)(0,0), double());
68 std::tr1::reference_wrapper<double (*)(int, char)>* pr2b;
69 verify_return_type((*pr2b)(0,0), double());
70 std::tr1::reference_wrapper<int (test_type::*)(char)>* pr3b;
71 verify_return_type((*pr3b)(ptt,zero), int());
72 std::tr1::reference_wrapper<int (test_type::*)(char)const>* pr4b;
73 verify_return_type((*pr4b)(cptt,zero), int());
74 std::tr1::reference_wrapper<functor2>* pr5b;
75 verify_return_type((*pr5b)(zero, zero), double());
76
77 // check implicit convertion:
78 int i = 0;
79 int& ri = std::tr1::ref(i);
80 const int& cri = std::tr1::cref(i);
81 }