]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/type_traits/test/tricky_partial_spec_test.cpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / libs / type_traits / test / tricky_partial_spec_test.cpp
1
2 // (C) Copyright John Maddock 2000.
3 // Use, modification and distribution are subject to the
4 // Boost Software License, Version 1.0. (See accompanying file
5 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6
7 #ifdef TEST_STD
8 # include <type_traits>
9 #else
10 #include <boost/type_traits/alignment_of.hpp>
11 #include <boost/type_traits/has_nothrow_assign.hpp>
12 #include <boost/type_traits/has_nothrow_constructor.hpp>
13 #include <boost/type_traits/has_nothrow_copy.hpp>
14 #include <boost/type_traits/is_base_and_derived.hpp>
15 #include <boost/type_traits/is_base_of.hpp>
16 #include <boost/type_traits/is_same.hpp>
17 #include <boost/type_traits/is_convertible.hpp>
18 #include <boost/type_traits/is_polymorphic.hpp>
19 #include <boost/type_traits/is_member_pointer.hpp>
20 #include <boost/type_traits/is_member_object_pointer.hpp>
21 #include <boost/type_traits/is_member_function_pointer.hpp>
22 #include <boost/type_traits/is_pointer.hpp>
23 #endif
24 #include "test.hpp"
25 #include "check_integral_constant.hpp"
26 #include <stdexcept>
27 #include <new>
28 #include <exception>
29
30 //
31 // VC++ emits an awful lot of warnings unless we define these:
32 #ifdef BOOST_MSVC
33 # pragma warning(disable:4244)
34 #endif
35
36
37 template <class T>
38 struct align_calc
39 {
40 char padding;
41 T instance;
42 static std::ptrdiff_t get()
43 {
44 static align_calc<T> a;
45 return reinterpret_cast<const char*>(&(a.instance)) - reinterpret_cast<const char*>(&(a.padding));
46 }
47 };
48
49 #define ALIGNOF(x) align_calc<x>::get()
50
51
52 TT_TEST_BEGIN(tricky_partial_specialization_test)
53 //
54 // corner cases which don't compile without partial specialization
55 // support:
56 //
57 #ifndef TEST_VIA_STATIC_ASSERT
58
59 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::alignment_of<char&>::value, ALIGNOF(void*));
60 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::alignment_of<char (&)(int)>::value, ALIGNOF(void*));
61 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::alignment_of<char(&)[4]>::value, ALIGNOF(void*));
62
63 #endif
64
65 BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_of<Base&,Derived>::value), false);
66 BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_of<Base&,Derived&>::value), false);
67 BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_of<Base,Derived&>::value), false);
68 BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_of<Base,void>::value), false);
69 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
70 BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_of<Base&&,Derived>::value), false);
71 BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_of<Base&&,Derived&&>::value), false);
72 BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_of<Base,Derived&&>::value), false);
73 #endif
74
75 BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_same<void, int>::value), false);
76 BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_same<void, void>::value), true);
77 BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_same<void, const void>::value), false);
78 BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_same<test_abc1, test_abc1>::value), true);
79 BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_same<test_abc1, const test_abc1>::value), false);
80
81 BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_convertible<void,float>::value), false);
82
83 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_polymorphic<const UDT>::value, false);
84 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_polymorphic<volatile empty_UDT>::value, false);
85 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_polymorphic<const VB>::value, true);
86 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_polymorphic<const volatile VD>::value, true);
87 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_polymorphic<const test_abc1>::value, true);
88 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_polymorphic<volatile test_abc2>::value, true);
89 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_polymorphic<const std::exception>::value, true);
90 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_polymorphic<const std::bad_alloc>::value, true);
91 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_polymorphic<const std::runtime_error>::value, true);
92 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_polymorphic<const std::out_of_range>::value, true);
93 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_polymorphic<const std::range_error>::value, true);
94
95 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_pointer<const f1>::value, true);
96 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_pointer<volatile f1>::value, true);
97 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_pointer<const volatile f1>::value, true);
98
99 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_member_pointer<const f1>::value, false);
100 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_member_pointer<const mp>::value, true);
101 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_member_pointer<volatile mp>::value, true);
102 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_member_pointer<const volatile mp>::value, true);
103 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_member_pointer<const mf3>::value, true);
104 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_member_pointer<volatile mf3>::value, true);
105 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_member_pointer<const volatile mf3>::value, true);
106
107 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_member_object_pointer<const f1>::value, false);
108 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_member_object_pointer<const mp>::value, true);
109 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_member_object_pointer<volatile mp>::value, true);
110 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_member_object_pointer<const volatile mp>::value, true);
111 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_member_object_pointer<const mf3>::value, false);
112 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_member_object_pointer<volatile mf3>::value, false);
113 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_member_object_pointer<const volatile mf3>::value, false);
114
115 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_member_function_pointer<const f1>::value, false);
116 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_member_function_pointer<const mp>::value, false);
117 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_member_function_pointer<volatile mp>::value, false);
118 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_member_function_pointer<const volatile mp>::value, false);
119 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_member_function_pointer<const mf3>::value, true);
120 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_member_function_pointer<volatile mf3>::value, true);
121 BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_member_function_pointer<const volatile mf3>::value, true);
122
123 TT_TEST_END
124
125
126
127
128
129
130
131