]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/type_traits/test/common_type_2_test.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / type_traits / test / common_type_2_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 #define BOOST_COMMON_TYPE_DONT_USE_TYPEOF 1
9
10 #include "test.hpp"
11 #include "check_type.hpp"
12 #ifdef TEST_STD
13 # include <type_traits>
14 #else
15 # include <boost/type_traits/common_type.hpp>
16 #endif
17 #include <iostream>
18
19 #ifdef BOOST_INTEL
20 #pragma warning(disable: 304 383)
21 #endif
22
23 struct C1 {};
24
25 struct C2 {};
26
27
28 struct C3 : C2 {};
29 struct C1C2 {
30 C1C2() {}
31 C1C2(C1 const&) {}
32 C1C2(C2 const&) {}
33 C1C2& operator=(C1C2 const&) {
34 return *this;
35 }
36 };
37
38 template <typename C, typename A>
39 void proc2(typename boost::common_type<A, C>::type const& ) {}
40
41 template <typename C, typename A, typename B>
42 void proc3(typename boost::common_type<C, A, B>::type const& ) {}
43
44 template <typename C, typename A>
45 void assignation_2() {
46 typedef typename boost::common_type<A, C>::type AC;
47 A a;
48 C c;
49 AC ac;
50 ac=a;
51 ac=c;
52
53 proc2<C, A>(a);
54 proc2<C, A>(c);
55
56 }
57
58 template <typename C, typename A, typename B>
59 void assignation_3() {
60 typedef typename boost::common_type<C, A, B>::type ABC;
61 A a;
62 B b;
63 C c;
64 ABC abc;
65
66 abc=a;
67 abc=b;
68 abc=c;
69
70 proc3<C, A, B>(a);
71 proc3<C, A, B>(b);
72 proc3<C, A, B>(c);
73 }
74
75 C1C2 c1c2;
76 C1 c1;
77
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;}
82
83 C1C2& declval_C1C2() {return c1c2;}
84 C1& declval_C1(){return c1;}
85 bool declval_bool(){return true;}
86
87
88 TT_TEST_BEGIN(common_type)
89 {
90 #ifndef __SUNPRO_CC
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*);
102 #endif
103 typedef tt::common_type<int*, int volatile*>::type T5;
104 BOOST_CHECK_TYPE(T5, int volatile*);
105
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
114 #endif
115
116 typedef tt::common_type<C1C2, C1>::type t1;
117 BOOST_CHECK_TYPE(t1, C1C2);
118
119 BOOST_CHECK_TYPE(tt::common_type<int>::type, int);
120 BOOST_CHECK_TYPE(tt::common_type<char>::type, char);
121
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);
131 #endif
132 BOOST_CHECK_TYPE3(tt::common_type<char, double>::type, double);
133
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);
143 #endif
144 BOOST_CHECK_TYPE3(tt::common_type<unsigned char, double>::type, double);
145
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);
155 #endif
156 BOOST_CHECK_TYPE3(tt::common_type<short, double>::type, double);
157
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);
167 #endif
168 BOOST_CHECK_TYPE3(tt::common_type<unsigned short, double>::type, double);
169
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);
179 #endif
180 BOOST_CHECK_TYPE3(tt::common_type<int, double>::type, double);
181
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);
191 #endif
192 BOOST_CHECK_TYPE3(tt::common_type<unsigned int, double>::type, double);
193
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);
204 #endif
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);
214 #endif
215 BOOST_CHECK_TYPE3(tt::common_type<double, double>::type, double);
216
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);
220 #endif
221 }
222 TT_TEST_END