]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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 | ||
7c673cae FG |
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 | |
11fdf7f2 TL |
24 | #include "test.hpp" |
25 | #include "check_integral_constant.hpp" | |
7c673cae FG |
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 | ||
58 | BOOST_CHECK_INTEGRAL_CONSTANT(::tt::alignment_of<char&>::value, ALIGNOF(void*)); | |
59 | BOOST_CHECK_INTEGRAL_CONSTANT(::tt::alignment_of<char (&)(int)>::value, ALIGNOF(void*)); | |
60 | BOOST_CHECK_INTEGRAL_CONSTANT(::tt::alignment_of<char(&)[4]>::value, ALIGNOF(void*)); | |
61 | ||
62 | BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_of<Base&,Derived>::value), false); | |
63 | BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_of<Base&,Derived&>::value), false); | |
64 | BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_of<Base,Derived&>::value), false); | |
65 | BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_of<Base,void>::value), false); | |
66 | #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES | |
67 | BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_of<Base&&,Derived>::value), false); | |
68 | BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_of<Base&&,Derived&&>::value), false); | |
69 | BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_of<Base,Derived&&>::value), false); | |
70 | #endif | |
71 | ||
72 | BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_same<void, int>::value), false); | |
73 | BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_same<void, void>::value), true); | |
74 | BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_same<void, const void>::value), false); | |
75 | BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_same<test_abc1, test_abc1>::value), true); | |
76 | BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_same<test_abc1, const test_abc1>::value), false); | |
77 | ||
78 | BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_convertible<void,float>::value), false); | |
79 | ||
80 | BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_polymorphic<const UDT>::value, false); | |
81 | BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_polymorphic<volatile empty_UDT>::value, false); | |
82 | BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_polymorphic<const VB>::value, true); | |
83 | BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_polymorphic<const volatile VD>::value, true); | |
84 | BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_polymorphic<const test_abc1>::value, true); | |
85 | BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_polymorphic<volatile test_abc2>::value, true); | |
86 | BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_polymorphic<const std::exception>::value, true); | |
87 | BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_polymorphic<const std::bad_alloc>::value, true); | |
88 | BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_polymorphic<const std::runtime_error>::value, true); | |
89 | BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_polymorphic<const std::out_of_range>::value, true); | |
90 | BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_polymorphic<const std::range_error>::value, true); | |
91 | ||
92 | BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_pointer<const f1>::value, true); | |
93 | BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_pointer<volatile f1>::value, true); | |
94 | BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_pointer<const volatile f1>::value, true); | |
95 | ||
96 | BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_member_pointer<const f1>::value, false); | |
97 | BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_member_pointer<const mp>::value, true); | |
98 | BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_member_pointer<volatile mp>::value, true); | |
99 | BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_member_pointer<const volatile mp>::value, true); | |
100 | BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_member_pointer<const mf3>::value, true); | |
101 | BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_member_pointer<volatile mf3>::value, true); | |
102 | BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_member_pointer<const volatile mf3>::value, true); | |
103 | ||
104 | BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_member_object_pointer<const f1>::value, false); | |
105 | BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_member_object_pointer<const mp>::value, true); | |
106 | BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_member_object_pointer<volatile mp>::value, true); | |
107 | BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_member_object_pointer<const volatile mp>::value, true); | |
108 | BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_member_object_pointer<const mf3>::value, false); | |
109 | BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_member_object_pointer<volatile mf3>::value, false); | |
110 | BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_member_object_pointer<const volatile mf3>::value, false); | |
111 | ||
112 | BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_member_function_pointer<const f1>::value, false); | |
113 | BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_member_function_pointer<const mp>::value, false); | |
114 | BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_member_function_pointer<volatile mp>::value, false); | |
115 | BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_member_function_pointer<const volatile mp>::value, false); | |
116 | BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_member_function_pointer<const mf3>::value, true); | |
117 | BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_member_function_pointer<volatile mf3>::value, true); | |
118 | BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_member_function_pointer<const volatile mf3>::value, true); | |
119 | ||
120 | TT_TEST_END | |
121 | ||
122 | ||
123 | ||
124 | ||
125 | ||
126 | ||
127 | ||
128 |