]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/type_traits/test/common_type_test.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / type_traits / test / common_type_test.cpp
1 // common_type_test.cpp ----------------------------------------------------//
2
3 // Copyright 2010 Beman Dawes
4
5 // Distributed under the Boost Software License, Version 1.0.
6 // See http://www.boost.org/LICENSE_1_0.txt
7
8 #include "test.hpp"
9 #include "check_type.hpp"
10 #ifdef TEST_STD
11 # include <type_traits>
12 #else
13 # include <boost/type_traits/common_type.hpp>
14 #endif
15 #include <iostream>
16
17 #ifdef BOOST_INTEL
18 #pragma warning(disable: 304 383)
19 #endif
20
21 struct C1 {};
22
23 struct C2 {};
24
25
26 struct C3 : C2 {};
27 struct C1C2 {
28 C1C2() {}
29 C1C2(C1 const&) {}
30 C1C2(C2 const&) {}
31 C1C2& operator=(C1C2 const&) {
32 return *this;
33 }
34 };
35
36 template <typename C, typename A>
37 void proc2(typename boost::common_type<A, C>::type const& ) {}
38
39 template <typename C, typename A, typename B>
40 void proc3(typename boost::common_type<C, A, B>::type const& ) {}
41
42 template <typename C, typename A>
43 void assignation_2() {
44 typedef typename boost::common_type<A, C>::type AC;
45 A a;
46 C c;
47 AC ac;
48 ac=a;
49 ac=c;
50
51 proc2<C, A>(a);
52 proc2<C, A>(c);
53
54 }
55
56 template <typename C, typename A, typename B>
57 void assignation_3() {
58 typedef typename boost::common_type<C, A, B>::type ABC;
59 A a;
60 B b;
61 C c;
62 ABC abc;
63
64 abc=a;
65 abc=b;
66 abc=c;
67
68 proc3<C, A, B>(a);
69 proc3<C, A, B>(b);
70 proc3<C, A, B>(c);
71 }
72
73 C1C2 c1c2;
74 C1 c1;
75
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;}
80
81 C1C2& declval_C1C2() {return c1c2;}
82 C1& declval_C1(){return c1;}
83 bool declval_bool(){return true;}
84
85
86 TT_TEST_BEGIN(common_type)
87 {
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*);
99 #endif
100 typedef tt::common_type<int*, int volatile*>::type T5;
101 BOOST_CHECK_TYPE(T5, int volatile*);
102
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
111
112 BOOST_CHECK_TYPE(tt::common_type<int>::type, int);
113 BOOST_CHECK_TYPE(tt::common_type<char>::type, char);
114
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);
124 #endif
125 BOOST_CHECK_TYPE3(tt::common_type<char, double>::type, double);
126
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);
136 #endif
137 BOOST_CHECK_TYPE3(tt::common_type<unsigned char, double>::type, double);
138
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);
148 #endif
149 BOOST_CHECK_TYPE3(tt::common_type<short, double>::type, double);
150
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);
160 #endif
161 BOOST_CHECK_TYPE3(tt::common_type<unsigned short, double>::type, double);
162
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);
172 #endif
173 BOOST_CHECK_TYPE3(tt::common_type<int, double>::type, double);
174
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);
184 #endif
185 BOOST_CHECK_TYPE3(tt::common_type<unsigned int, double>::type, double);
186
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);
197 #endif
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);
207 #endif
208 BOOST_CHECK_TYPE3(tt::common_type<double, double>::type, double);
209
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);
213 #endif
214
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);
220 }
221 TT_TEST_END