]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/type_traits/test/common_type_test.cpp
1 // common_type_test.cpp ----------------------------------------------------//
3 // Copyright 2010 Beman Dawes
5 // Distributed under the Boost Software License, Version 1.0.
6 // See http://www.boost.org/LICENSE_1_0.txt
9 #include "check_type.hpp"
11 # include <type_traits>
13 # include <boost/type_traits/common_type.hpp>
18 #pragma warning(disable: 304 383)
31 C1C2
& operator=(C1C2
const&) {
36 template <typename C
, typename A
>
37 void proc2(typename
boost::common_type
<A
, C
>::type
const& ) {}
39 template <typename C
, typename A
, typename B
>
40 void proc3(typename
boost::common_type
<C
, A
, B
>::type
const& ) {}
42 template <typename C
, typename A
>
43 void assignation_2() {
44 typedef typename
boost::common_type
<A
, C
>::type AC
;
56 template <typename C
, typename A
, typename B
>
57 void assignation_3() {
58 typedef typename
boost::common_type
<C
, A
, B
>::type ABC
;
76 int f(C1C2
) { return 1;}
77 int f(C1
) { return 2;}
78 template <typename OSTREAM
>
79 OSTREAM
& operator<<(OSTREAM
& os
, C1
const&) {return os
;}
81 C1C2
& declval_C1C2() {return c1c2
;}
82 C1
& declval_C1(){return c1
;}
83 bool declval_bool(){return true;}
86 TT_TEST_BEGIN(common_type
)
88 assignation_2
<C1C2
, C1
>();
89 typedef tt::common_type
<C1C2
&, C1
&>::type T1
;
90 BOOST_CHECK_TYPE(T1
, C1C2
);
91 typedef tt::common_type
<C3
*, C2
*>::type T2
;
92 BOOST_CHECK_TYPE(T2
, C2
*);
93 typedef tt::common_type
<int*, int const*>::type T3
;
94 BOOST_CHECK_TYPE(T3
, int const*);
95 #if defined(BOOST_NO_CXX11_DECLTYPE) && !defined(BOOST_COMMON_TYPE_DONT_USE_TYPEOF)
96 // fails if BOOST_COMMON_TYPE_DONT_USE_TYPEOF:
97 typedef tt::common_type
<int volatile*, int const*>::type T4
;
98 BOOST_CHECK_TYPE(T4
, int const volatile*);
100 typedef tt::common_type
<int*, int volatile*>::type T5
;
101 BOOST_CHECK_TYPE(T5
, int volatile*);
103 assignation_2
<C1
, C1C2
>();
104 assignation_2
<C1C2
, C2
>();
105 assignation_2
<C2
, C1C2
>();
106 assignation_3
<C1
, C1C2
, C2
>();
107 assignation_3
<C1C2
, C1
, C2
>();
108 assignation_3
<C2
, C1C2
, C1
>();
109 assignation_3
<C1C2
, C2
, C1
>();
110 //assignation_3<C1, C2, C1C2>(); // fails because the common type is the third
112 BOOST_CHECK_TYPE(tt::common_type
<int>::type
, int);
113 BOOST_CHECK_TYPE(tt::common_type
<char>::type
, char);
115 BOOST_CHECK_TYPE3(tt::common_type
<char, char>::type
, char);
116 BOOST_CHECK_TYPE3(tt::common_type
<char, unsigned char>::type
, int);
117 BOOST_CHECK_TYPE3(tt::common_type
<char, short>::type
, int);
118 BOOST_CHECK_TYPE3(tt::common_type
<char, unsigned short>::type
, int);
119 BOOST_CHECK_TYPE3(tt::common_type
<char, int>::type
, int);
120 BOOST_CHECK_TYPE3(tt::common_type
<char, unsigned int>::type
, unsigned int);
121 #ifndef BOOST_NO_LONG_LONG
122 BOOST_CHECK_TYPE3(tt::common_type
<char, boost::long_long_type
>::type
, boost::long_long_type
);
123 BOOST_CHECK_TYPE3(tt::common_type
<char, boost::ulong_long_type
>::type
, boost::ulong_long_type
);
125 BOOST_CHECK_TYPE3(tt::common_type
<char, double>::type
, double);
127 BOOST_CHECK_TYPE3(tt::common_type
<unsigned char, char>::type
, int);
128 BOOST_CHECK_TYPE3(tt::common_type
<unsigned char, unsigned char>::type
, unsigned char);
129 BOOST_CHECK_TYPE3(tt::common_type
<unsigned char, short>::type
, int);
130 BOOST_CHECK_TYPE3(tt::common_type
<unsigned char, unsigned short>::type
, int);
131 BOOST_CHECK_TYPE3(tt::common_type
<unsigned char, int>::type
, int);
132 BOOST_CHECK_TYPE3(tt::common_type
<unsigned char, unsigned int>::type
, unsigned int);
133 #ifndef BOOST_NO_LONG_LONG
134 BOOST_CHECK_TYPE3(tt::common_type
<unsigned char, boost::long_long_type
>::type
, boost::long_long_type
);
135 BOOST_CHECK_TYPE3(tt::common_type
<unsigned char, boost::ulong_long_type
>::type
, boost::ulong_long_type
);
137 BOOST_CHECK_TYPE3(tt::common_type
<unsigned char, double>::type
, double);
139 BOOST_CHECK_TYPE3(tt::common_type
<short, char>::type
, int);
140 BOOST_CHECK_TYPE3(tt::common_type
<short, unsigned char>::type
, int);
141 BOOST_CHECK_TYPE3(tt::common_type
<short, short>::type
, short);
142 BOOST_CHECK_TYPE3(tt::common_type
<short, unsigned short>::type
, int);
143 BOOST_CHECK_TYPE3(tt::common_type
<short, int>::type
, int);
144 BOOST_CHECK_TYPE3(tt::common_type
<short, unsigned int>::type
, unsigned int);
145 #ifndef BOOST_NO_LONG_LONG
146 BOOST_CHECK_TYPE3(tt::common_type
<short, boost::long_long_type
>::type
, boost::long_long_type
);
147 BOOST_CHECK_TYPE3(tt::common_type
<short, boost::ulong_long_type
>::type
, boost::ulong_long_type
);
149 BOOST_CHECK_TYPE3(tt::common_type
<short, double>::type
, double);
151 BOOST_CHECK_TYPE3(tt::common_type
<unsigned short, char>::type
, int);
152 BOOST_CHECK_TYPE3(tt::common_type
<unsigned short, unsigned char>::type
, int);
153 BOOST_CHECK_TYPE3(tt::common_type
<unsigned short, short>::type
, int);
154 BOOST_CHECK_TYPE3(tt::common_type
<unsigned short, unsigned short>::type
, unsigned short);
155 BOOST_CHECK_TYPE3(tt::common_type
<unsigned short, int>::type
, int);
156 BOOST_CHECK_TYPE3(tt::common_type
<unsigned short, unsigned int>::type
, unsigned int);
157 #ifndef BOOST_NO_LONG_LONG
158 BOOST_CHECK_TYPE3(tt::common_type
<unsigned short, boost::long_long_type
>::type
, boost::long_long_type
);
159 BOOST_CHECK_TYPE3(tt::common_type
<unsigned short, boost::ulong_long_type
>::type
, boost::ulong_long_type
);
161 BOOST_CHECK_TYPE3(tt::common_type
<unsigned short, double>::type
, double);
163 BOOST_CHECK_TYPE3(tt::common_type
<int, char>::type
, int);
164 BOOST_CHECK_TYPE3(tt::common_type
<int, unsigned char>::type
, int);
165 BOOST_CHECK_TYPE3(tt::common_type
<int, short>::type
, int);
166 BOOST_CHECK_TYPE3(tt::common_type
<int, unsigned short>::type
, int);
167 BOOST_CHECK_TYPE3(tt::common_type
<int, int>::type
, int);
168 BOOST_CHECK_TYPE3(tt::common_type
<int, unsigned int>::type
, unsigned int);
169 #ifndef BOOST_NO_LONG_LONG
170 BOOST_CHECK_TYPE3(tt::common_type
<int, boost::long_long_type
>::type
, boost::long_long_type
);
171 BOOST_CHECK_TYPE3(tt::common_type
<int, boost::ulong_long_type
>::type
, boost::ulong_long_type
);
173 BOOST_CHECK_TYPE3(tt::common_type
<int, double>::type
, double);
175 BOOST_CHECK_TYPE3(tt::common_type
<unsigned int, char>::type
, unsigned int);
176 BOOST_CHECK_TYPE3(tt::common_type
<unsigned int, unsigned char>::type
, unsigned int);
177 BOOST_CHECK_TYPE3(tt::common_type
<unsigned int, short>::type
, unsigned int);
178 BOOST_CHECK_TYPE3(tt::common_type
<unsigned int, unsigned short>::type
, unsigned int);
179 BOOST_CHECK_TYPE3(tt::common_type
<unsigned int, int>::type
, unsigned int);
180 BOOST_CHECK_TYPE3(tt::common_type
<unsigned int, unsigned int>::type
, unsigned int);
181 #ifndef BOOST_NO_LONG_LONG
182 BOOST_CHECK_TYPE3(tt::common_type
<unsigned int, boost::long_long_type
>::type
, boost::long_long_type
);
183 BOOST_CHECK_TYPE3(tt::common_type
<unsigned int, boost::ulong_long_type
>::type
, boost::ulong_long_type
);
185 BOOST_CHECK_TYPE3(tt::common_type
<unsigned int, double>::type
, double);
187 #ifndef BOOST_NO_LONG_LONG
188 BOOST_CHECK_TYPE3(tt::common_type
<boost::long_long_type
, char>::type
, boost::long_long_type
);
189 BOOST_CHECK_TYPE3(tt::common_type
<boost::long_long_type
, unsigned char>::type
, boost::long_long_type
);
190 BOOST_CHECK_TYPE3(tt::common_type
<boost::long_long_type
, short>::type
, boost::long_long_type
);
191 BOOST_CHECK_TYPE3(tt::common_type
<boost::long_long_type
, unsigned short>::type
, boost::long_long_type
);
192 BOOST_CHECK_TYPE3(tt::common_type
<boost::long_long_type
, int>::type
, boost::long_long_type
);
193 BOOST_CHECK_TYPE3(tt::common_type
<boost::long_long_type
, unsigned int>::type
, boost::long_long_type
);
194 BOOST_CHECK_TYPE3(tt::common_type
<boost::long_long_type
, boost::long_long_type
>::type
, boost::long_long_type
);
195 BOOST_CHECK_TYPE3(tt::common_type
<boost::long_long_type
, boost::ulong_long_type
>::type
, boost::ulong_long_type
);
196 BOOST_CHECK_TYPE3(tt::common_type
<boost::long_long_type
, double>::type
, double);
198 BOOST_CHECK_TYPE3(tt::common_type
<double, char>::type
, double);
199 BOOST_CHECK_TYPE3(tt::common_type
<double, unsigned char>::type
, double);
200 BOOST_CHECK_TYPE3(tt::common_type
<double, short>::type
, double);
201 BOOST_CHECK_TYPE3(tt::common_type
<double, unsigned short>::type
, double);
202 BOOST_CHECK_TYPE3(tt::common_type
<double, int>::type
, double);
203 BOOST_CHECK_TYPE3(tt::common_type
<double, unsigned int>::type
, double);
204 #ifndef BOOST_NO_LONG_LONG
205 BOOST_CHECK_TYPE3(tt::common_type
<double, boost::long_long_type
>::type
, double);
206 BOOST_CHECK_TYPE3(tt::common_type
<double, boost::ulong_long_type
>::type
, double);
208 BOOST_CHECK_TYPE3(tt::common_type
<double, double>::type
, double);
210 BOOST_CHECK_TYPE4(tt::common_type
<double, char, int>::type
, double);
211 #ifndef BOOST_NO_LONG_LONG
212 BOOST_CHECK_TYPE4(tt::common_type
<unsigned, char, boost::long_long_type
>::type
, boost::long_long_type
);
215 //changes related to defect LWG2141
216 BOOST_CHECK_TYPE(tt::common_type
<int&>::type
, int);
217 BOOST_CHECK_TYPE(tt::common_type
<const int>::type
, int);
218 BOOST_CHECK_TYPE3(tt::common_type
<const int, const int>::type
, int);
219 BOOST_CHECK_TYPE3(tt::common_type
<const int, const long>::type
, long);