]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/type_traits/test/common_type_2_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
8 #define BOOST_COMMON_TYPE_DONT_USE_TYPEOF 1
11 #include "check_type.hpp"
13 # include <type_traits>
15 # include <boost/type_traits/common_type.hpp>
20 #pragma warning(disable: 304 383)
33 C1C2
& operator=(C1C2
const&) {
38 template <typename C
, typename A
>
39 void proc2(typename
boost::common_type
<A
, C
>::type
const& ) {}
41 template <typename C
, typename A
, typename B
>
42 void proc3(typename
boost::common_type
<C
, A
, B
>::type
const& ) {}
44 template <typename C
, typename A
>
45 void assignation_2() {
46 typedef typename
boost::common_type
<A
, C
>::type AC
;
58 template <typename C
, typename A
, typename B
>
59 void assignation_3() {
60 typedef typename
boost::common_type
<C
, A
, B
>::type ABC
;
78 int f(C1C2
) { return 1;}
79 int f(C1
) { return 2;}
80 template <typename OSTREAM
>
81 OSTREAM
& operator<<(OSTREAM
& os
, C1
const&) {return os
;}
83 C1C2
& declval_C1C2() {return c1c2
;}
84 C1
& declval_C1(){return c1
;}
85 bool declval_bool(){return true;}
88 TT_TEST_BEGIN(common_type
)
91 assignation_2
<C1C2
, C1
>();
92 typedef tt::common_type
<C1C2
&, C1
&>::type T1
;
93 BOOST_CHECK_TYPE(T1
, C1C2
);
94 typedef tt::common_type
<C3
*, C2
*>::type T2
;
95 BOOST_CHECK_TYPE(T2
, C2
*);
96 typedef tt::common_type
<int*, int const*>::type T3
;
97 BOOST_CHECK_TYPE(T3
, int const*);
98 #if defined(BOOST_NO_CXX11_DECLTYPE) && !defined(BOOST_COMMON_TYPE_DONT_USE_TYPEOF)
99 // fails if BOOST_COMMON_TYPE_DONT_USE_TYPEOF:
100 typedef tt::common_type
<int volatile*, int const*>::type T4
;
101 BOOST_CHECK_TYPE(T4
, int const volatile*);
103 typedef tt::common_type
<int*, int volatile*>::type T5
;
104 BOOST_CHECK_TYPE(T5
, int volatile*);
106 assignation_2
<C1
, C1C2
>();
107 assignation_2
<C1C2
, C2
>();
108 assignation_2
<C2
, C1C2
>();
109 assignation_3
<C1
, C1C2
, C2
>();
110 assignation_3
<C1C2
, C1
, C2
>();
111 assignation_3
<C2
, C1C2
, C1
>();
112 assignation_3
<C1C2
, C2
, C1
>();
113 //assignation_3<C1, C2, C1C2>(); // fails because the common type is the third
116 typedef tt::common_type
<C1C2
, C1
>::type t1
;
117 BOOST_CHECK_TYPE(t1
, C1C2
);
119 BOOST_CHECK_TYPE(tt::common_type
<int>::type
, int);
120 BOOST_CHECK_TYPE(tt::common_type
<char>::type
, char);
122 BOOST_CHECK_TYPE3(tt::common_type
<char, char>::type
, char);
123 BOOST_CHECK_TYPE3(tt::common_type
<char, unsigned char>::type
, int);
124 BOOST_CHECK_TYPE3(tt::common_type
<char, short>::type
, int);
125 BOOST_CHECK_TYPE3(tt::common_type
<char, unsigned short>::type
, int);
126 BOOST_CHECK_TYPE3(tt::common_type
<char, int>::type
, int);
127 BOOST_CHECK_TYPE3(tt::common_type
<char, unsigned int>::type
, unsigned int);
128 #ifndef BOOST_NO_LONG_LONG
129 BOOST_CHECK_TYPE3(tt::common_type
<char, boost::long_long_type
>::type
, boost::long_long_type
);
130 BOOST_CHECK_TYPE3(tt::common_type
<char, boost::ulong_long_type
>::type
, boost::ulong_long_type
);
132 BOOST_CHECK_TYPE3(tt::common_type
<char, double>::type
, double);
134 BOOST_CHECK_TYPE3(tt::common_type
<unsigned char, char>::type
, int);
135 BOOST_CHECK_TYPE3(tt::common_type
<unsigned char, unsigned char>::type
, unsigned char);
136 BOOST_CHECK_TYPE3(tt::common_type
<unsigned char, short>::type
, int);
137 BOOST_CHECK_TYPE3(tt::common_type
<unsigned char, unsigned short>::type
, int);
138 BOOST_CHECK_TYPE3(tt::common_type
<unsigned char, int>::type
, int);
139 BOOST_CHECK_TYPE3(tt::common_type
<unsigned char, unsigned int>::type
, unsigned int);
140 #ifndef BOOST_NO_LONG_LONG
141 BOOST_CHECK_TYPE3(tt::common_type
<unsigned char, boost::long_long_type
>::type
, boost::long_long_type
);
142 BOOST_CHECK_TYPE3(tt::common_type
<unsigned char, boost::ulong_long_type
>::type
, boost::ulong_long_type
);
144 BOOST_CHECK_TYPE3(tt::common_type
<unsigned char, double>::type
, double);
146 BOOST_CHECK_TYPE3(tt::common_type
<short, char>::type
, int);
147 BOOST_CHECK_TYPE3(tt::common_type
<short, unsigned char>::type
, int);
148 BOOST_CHECK_TYPE3(tt::common_type
<short, short>::type
, short);
149 BOOST_CHECK_TYPE3(tt::common_type
<short, unsigned short>::type
, int);
150 BOOST_CHECK_TYPE3(tt::common_type
<short, int>::type
, int);
151 BOOST_CHECK_TYPE3(tt::common_type
<short, unsigned int>::type
, unsigned int);
152 #ifndef BOOST_NO_LONG_LONG
153 BOOST_CHECK_TYPE3(tt::common_type
<short, boost::long_long_type
>::type
, boost::long_long_type
);
154 BOOST_CHECK_TYPE3(tt::common_type
<short, boost::ulong_long_type
>::type
, boost::ulong_long_type
);
156 BOOST_CHECK_TYPE3(tt::common_type
<short, double>::type
, double);
158 BOOST_CHECK_TYPE3(tt::common_type
<unsigned short, char>::type
, int);
159 BOOST_CHECK_TYPE3(tt::common_type
<unsigned short, unsigned char>::type
, int);
160 BOOST_CHECK_TYPE3(tt::common_type
<unsigned short, short>::type
, int);
161 BOOST_CHECK_TYPE3(tt::common_type
<unsigned short, unsigned short>::type
, unsigned short);
162 BOOST_CHECK_TYPE3(tt::common_type
<unsigned short, int>::type
, int);
163 BOOST_CHECK_TYPE3(tt::common_type
<unsigned short, unsigned int>::type
, unsigned int);
164 #ifndef BOOST_NO_LONG_LONG
165 BOOST_CHECK_TYPE3(tt::common_type
<unsigned short, boost::long_long_type
>::type
, boost::long_long_type
);
166 BOOST_CHECK_TYPE3(tt::common_type
<unsigned short, boost::ulong_long_type
>::type
, boost::ulong_long_type
);
168 BOOST_CHECK_TYPE3(tt::common_type
<unsigned short, double>::type
, double);
170 BOOST_CHECK_TYPE3(tt::common_type
<int, char>::type
, int);
171 BOOST_CHECK_TYPE3(tt::common_type
<int, unsigned char>::type
, int);
172 BOOST_CHECK_TYPE3(tt::common_type
<int, short>::type
, int);
173 BOOST_CHECK_TYPE3(tt::common_type
<int, unsigned short>::type
, int);
174 BOOST_CHECK_TYPE3(tt::common_type
<int, int>::type
, int);
175 BOOST_CHECK_TYPE3(tt::common_type
<int, unsigned int>::type
, unsigned int);
176 #ifndef BOOST_NO_LONG_LONG
177 BOOST_CHECK_TYPE3(tt::common_type
<int, boost::long_long_type
>::type
, boost::long_long_type
);
178 BOOST_CHECK_TYPE3(tt::common_type
<int, boost::ulong_long_type
>::type
, boost::ulong_long_type
);
180 BOOST_CHECK_TYPE3(tt::common_type
<int, double>::type
, double);
182 BOOST_CHECK_TYPE3(tt::common_type
<unsigned int, char>::type
, unsigned int);
183 BOOST_CHECK_TYPE3(tt::common_type
<unsigned int, unsigned char>::type
, unsigned int);
184 BOOST_CHECK_TYPE3(tt::common_type
<unsigned int, short>::type
, unsigned int);
185 BOOST_CHECK_TYPE3(tt::common_type
<unsigned int, unsigned short>::type
, unsigned int);
186 BOOST_CHECK_TYPE3(tt::common_type
<unsigned int, int>::type
, unsigned int);
187 BOOST_CHECK_TYPE3(tt::common_type
<unsigned int, unsigned int>::type
, unsigned int);
188 #ifndef BOOST_NO_LONG_LONG
189 BOOST_CHECK_TYPE3(tt::common_type
<unsigned int, boost::long_long_type
>::type
, boost::long_long_type
);
190 BOOST_CHECK_TYPE3(tt::common_type
<unsigned int, boost::ulong_long_type
>::type
, boost::ulong_long_type
);
192 BOOST_CHECK_TYPE3(tt::common_type
<unsigned int, double>::type
, double);
194 #ifndef BOOST_NO_LONG_LONG
195 BOOST_CHECK_TYPE3(tt::common_type
<boost::long_long_type
, char>::type
, boost::long_long_type
);
196 BOOST_CHECK_TYPE3(tt::common_type
<boost::long_long_type
, unsigned char>::type
, boost::long_long_type
);
197 BOOST_CHECK_TYPE3(tt::common_type
<boost::long_long_type
, short>::type
, boost::long_long_type
);
198 BOOST_CHECK_TYPE3(tt::common_type
<boost::long_long_type
, unsigned short>::type
, boost::long_long_type
);
199 BOOST_CHECK_TYPE3(tt::common_type
<boost::long_long_type
, int>::type
, boost::long_long_type
);
200 BOOST_CHECK_TYPE3(tt::common_type
<boost::long_long_type
, unsigned int>::type
, boost::long_long_type
);
201 BOOST_CHECK_TYPE3(tt::common_type
<boost::long_long_type
, boost::long_long_type
>::type
, boost::long_long_type
);
202 BOOST_CHECK_TYPE3(tt::common_type
<boost::long_long_type
, boost::ulong_long_type
>::type
, boost::ulong_long_type
);
203 BOOST_CHECK_TYPE3(tt::common_type
<boost::long_long_type
, double>::type
, double);
205 BOOST_CHECK_TYPE3(tt::common_type
<double, char>::type
, double);
206 BOOST_CHECK_TYPE3(tt::common_type
<double, unsigned char>::type
, double);
207 BOOST_CHECK_TYPE3(tt::common_type
<double, short>::type
, double);
208 BOOST_CHECK_TYPE3(tt::common_type
<double, unsigned short>::type
, double);
209 BOOST_CHECK_TYPE3(tt::common_type
<double, int>::type
, double);
210 BOOST_CHECK_TYPE3(tt::common_type
<double, unsigned int>::type
, double);
211 #ifndef BOOST_NO_LONG_LONG
212 BOOST_CHECK_TYPE3(tt::common_type
<double, boost::long_long_type
>::type
, double);
213 BOOST_CHECK_TYPE3(tt::common_type
<double, boost::ulong_long_type
>::type
, double);
215 BOOST_CHECK_TYPE3(tt::common_type
<double, double>::type
, double);
217 BOOST_CHECK_TYPE4(tt::common_type
<double, char, int>::type
, double);
218 #ifndef BOOST_NO_LONG_LONG
219 BOOST_CHECK_TYPE4(tt::common_type
<unsigned, char, boost::long_long_type
>::type
, boost::long_long_type
);