]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/type_traits/test/test.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / type_traits / test / test.hpp
CommitLineData
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
7#ifndef TT_TEST_HPP
8#define TT_TEST_HPP
9
10#include <boost/config.hpp>
b32b8144 11#include <boost/detail/workaround.hpp>
7c673cae
FG
12
13#if defined(_WIN32_WCE) && defined(BOOST_MSVC)
14#pragma warning(disable:4201)
15#endif
16
17#include <boost/noncopyable.hpp>
18#include <iostream>
19#include <typeinfo>
20
21#ifdef __BORLANDC__
22// we have to turn off these warnings otherwise we get swamped by the things:
23#pragma option -w-8008 -w-8066
24#endif
25
26#ifdef _MSC_VER
27// We have to turn off warnings that occur within the test suite:
28#pragma warning(disable:4127)
29#endif
30#ifdef BOOST_INTEL
31// remark #1418: external function definition with no prior declaration
32// remark #981: operands are evaluated in unspecified order
33#pragma warning(disable:1418 981)
34#endif
35
36#ifdef BOOST_INTEL
37// turn off warnings from this header:
38#pragma warning(push)
39#pragma warning(disable:444)
40#endif
41
42//
43// basic configuration:
44//
45#ifdef TEST_STD
46
47#define tt std::tr1
48
49//#define TYPE_TRAITS(x) <type_traits>
50//#define TYPE_COMPARE(x) <type_compare>
51//#define TYPE_TRANSFORM(x) <type_transform>
52
53#else
54
55#define tt boost
56
57//#define TYPE_TRAITS(x) BOOST_STRINGIZE(boost/type_traits/x.hpp)
58//#define TYPE_COMPARE(x) BOOST_STRINGIZE(boost/type_traits/x.hpp)
59//#define TYPE_TRANSFORM(x) BOOST_STRINGIZE(boost/type_traits/x.hpp)
60
61#endif
62
63//
64// replacements for Unit test macros:
65//
66int error_count = 0;
67
68#define BOOST_CHECK_MESSAGE(pred, message)\
69 do{\
70 if(!(pred))\
71 {\
72 std::cerr << __FILE__ << ":" << __LINE__ << ": " << message << std::endl;\
73 ++error_count;\
74 }\
75 }while(0)
76
77#define BOOST_WARN_MESSAGE(pred, message)\
78 do{\
79 if(!(pred))\
80 {\
81 std::cerr << __FILE__ << ":" << __LINE__ << ": " << message << std::endl;\
82 }\
83 }while(0)
84
85#define BOOST_TEST_MESSAGE(message)\
86 do{ std::cout << __FILE__ << ":" << __LINE__ << ": " << message << std::endl; }while(0)
87
88#define BOOST_CHECK(pred)\
89 do{ \
90 if(!(pred)){\
91 std::cout << __FILE__ << ":" << __LINE__ << ": Error in " << BOOST_STRINGIZE(pred) << std::endl;\
92 ++error_count;\
93 } \
94 }while(0)
95
96#define TT_TEST_BEGIN(trait_name)\
97 int main(){
98#define TT_TEST_END return error_count; }
99
b32b8144
FG
100#if !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES) && !BOOST_WORKAROUND(BOOST_GCC, < 40704)
101
102#define TRANSFORM_CHECK_ALIASES(name, from_suffix, to_suffix)\
103 BOOST_CHECK_TYPE(bool to_suffix, name##_t<bool from_suffix>);\
104 BOOST_CHECK_TYPE(char to_suffix, name##_t<char from_suffix>);\
105 BOOST_CHECK_TYPE(wchar_t to_suffix, name##_t<wchar_t from_suffix>);\
106 BOOST_CHECK_TYPE(signed char to_suffix, name##_t<signed char from_suffix>);\
107 BOOST_CHECK_TYPE(unsigned char to_suffix, name##_t<unsigned char from_suffix>);\
108 BOOST_CHECK_TYPE(short to_suffix, name##_t<short from_suffix>);\
109 BOOST_CHECK_TYPE(unsigned short to_suffix, name##_t<unsigned short from_suffix>);\
110 BOOST_CHECK_TYPE(int to_suffix, name##_t<int from_suffix>);\
111 BOOST_CHECK_TYPE(unsigned int to_suffix, name##_t<unsigned int from_suffix>);\
112 BOOST_CHECK_TYPE(long to_suffix, name##_t<long from_suffix>);\
113 BOOST_CHECK_TYPE(unsigned long to_suffix, name##_t<unsigned long from_suffix>);\
114 BOOST_CHECK_TYPE(float to_suffix, name##_t<float from_suffix>);\
115 BOOST_CHECK_TYPE(long double to_suffix, name##_t<long double from_suffix>);\
116 BOOST_CHECK_TYPE(double to_suffix, name##_t<double from_suffix>);\
117 BOOST_CHECK_TYPE(UDT to_suffix, name##_t<UDT from_suffix>);\
118 BOOST_CHECK_TYPE(enum1 to_suffix, name##_t<enum1 from_suffix>);
119
120#else
121
122#define TRANSFORM_CHECK_ALIASES(name, from_suffix, to_suffix) /**/
123
124#endif
7c673cae
FG
125
126#define TRANSFORM_CHECK(name, from_suffix, to_suffix)\
b32b8144 127 TRANSFORM_CHECK_ALIASES(name, from_suffix, to_suffix)\
7c673cae
FG
128 BOOST_CHECK_TYPE(bool to_suffix, name<bool from_suffix>::type);\
129 BOOST_CHECK_TYPE(char to_suffix, name<char from_suffix>::type);\
130 BOOST_CHECK_TYPE(wchar_t to_suffix, name<wchar_t from_suffix>::type);\
131 BOOST_CHECK_TYPE(signed char to_suffix, name<signed char from_suffix>::type);\
132 BOOST_CHECK_TYPE(unsigned char to_suffix, name<unsigned char from_suffix>::type);\
133 BOOST_CHECK_TYPE(short to_suffix, name<short from_suffix>::type);\
134 BOOST_CHECK_TYPE(unsigned short to_suffix, name<unsigned short from_suffix>::type);\
135 BOOST_CHECK_TYPE(int to_suffix, name<int from_suffix>::type);\
136 BOOST_CHECK_TYPE(unsigned int to_suffix, name<unsigned int from_suffix>::type);\
137 BOOST_CHECK_TYPE(long to_suffix, name<long from_suffix>::type);\
138 BOOST_CHECK_TYPE(unsigned long to_suffix, name<unsigned long from_suffix>::type);\
139 BOOST_CHECK_TYPE(float to_suffix, name<float from_suffix>::type);\
140 BOOST_CHECK_TYPE(long double to_suffix, name<long double from_suffix>::type);\
141 BOOST_CHECK_TYPE(double to_suffix, name<double from_suffix>::type);\
142 BOOST_CHECK_TYPE(UDT to_suffix, name<UDT from_suffix>::type);\
143 BOOST_CHECK_TYPE(enum1 to_suffix, name<enum1 from_suffix>::type);
144
145#define BOOST_DUMMY_MACRO_PARAM /**/
146
147#define BOOST_DECL_TRANSFORM_TEST(name, type, from, to)\
148void name(){ TRANSFORM_CHECK(type, from, to) }
149#define BOOST_DECL_TRANSFORM_TEST3(name, type, from)\
150void name(){ TRANSFORM_CHECK(type, from, BOOST_DUMMY_MACRO_PARAM) }
151#define BOOST_DECL_TRANSFORM_TEST2(name, type, to)\
152void name(){ TRANSFORM_CHECK(type, BOOST_DUMMY_MACRO_PARAM, to) }
153#define BOOST_DECL_TRANSFORM_TEST0(name, type)\
154void name(){ TRANSFORM_CHECK(type, BOOST_DUMMY_MACRO_PARAM, BOOST_DUMMY_MACRO_PARAM) }
155
156
157
158//
159// VC++ emits an awful lot of warnings unless we define these:
160#ifdef BOOST_MSVC
161# pragma warning(disable:4800)
162#endif
163
164//
165// define some test types:
166//
167enum enum_UDT{ one, two, three };
168struct UDT
169{
170 UDT();
171 ~UDT();
172 UDT(const UDT&);
173 UDT& operator=(const UDT&);
174 int i;
175
176 void f1();
177 int f2();
178 int f3(int);
179 int f4(int, float);
180};
181
182typedef void(*f1)();
183typedef int(*f2)(int);
184typedef int(*f3)(int, bool);
185typedef void (UDT::*mf1)();
186typedef int (UDT::*mf2)();
187typedef int (UDT::*mf3)(int);
188typedef int (UDT::*mf4)(int, float);
189typedef int (UDT::*mp);
190typedef int (UDT::*cmf)(int) const;
191
192// cv-qualifiers applied to reference types should have no effect
193// declare these here for later use with is_reference and remove_reference:
194# ifdef BOOST_MSVC
195# pragma warning(push)
196# pragma warning(disable: 4181)
197# elif defined(BOOST_INTEL)
198# pragma warning(push)
199# pragma warning(disable: 21)
200# endif
201//
202// This is intentional:
203// r_type and cr_type should be the same type
204// but some compilers wrongly apply cv-qualifiers
205// to reference types (this may generate a warning
206// on some compilers):
207//
208typedef int& r_type;
209#ifndef BOOST_INTEL
210typedef const r_type cr_type;
211#else
212// recent Intel compilers generate a hard error on the above:
213typedef r_type cr_type;
214#endif
215# ifdef BOOST_MSVC
216# pragma warning(pop)
217# elif defined(BOOST_INTEL)
218# pragma warning(pop)
219# pragma warning(disable: 985) // identifier truncated in debug information
220# endif
221
222struct POD_UDT { int x; };
223struct empty_UDT
224{
225 empty_UDT();
226 empty_UDT(const empty_UDT&);
227 ~empty_UDT();
228 empty_UDT& operator=(const empty_UDT&);
229 bool operator==(const empty_UDT&)const;
230};
231struct empty_POD_UDT
232{
233 bool operator==(const empty_POD_UDT&)const
234 { return true; }
235};
236union union_UDT
237{
238 int x;
239 double y;
240 ~union_UDT(){}
241};
242union POD_union_UDT
243{
244 int x;
245 double y;
246};
247union empty_union_UDT
248{
249 ~empty_union_UDT(){}
250};
251union empty_POD_union_UDT{};
252
253struct nothrow_copy_UDT
254{
255 nothrow_copy_UDT();
256 nothrow_copy_UDT(const nothrow_copy_UDT&)throw();
257 ~nothrow_copy_UDT(){}
258 nothrow_copy_UDT& operator=(const nothrow_copy_UDT&);
259 bool operator==(const nothrow_copy_UDT&)const
260 { return true; }
261};
262
263struct nothrow_assign_UDT
264{
265 nothrow_assign_UDT();
266 nothrow_assign_UDT(const nothrow_assign_UDT&);
267 ~nothrow_assign_UDT(){};
268 nothrow_assign_UDT& operator=(const nothrow_assign_UDT&)throw(){ return *this; }
269 bool operator==(const nothrow_assign_UDT&)const
270 { return true; }
271};
272
273#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
274struct nothrow_move_UDT
275{
276 nothrow_move_UDT();
277 nothrow_move_UDT(nothrow_move_UDT&&) throw();
278 nothrow_move_UDT& operator=(nothrow_move_UDT&&) throw();
279 bool operator==(const nothrow_move_UDT&)const
280 { return true; }
281};
282#endif
283
284
285struct nothrow_construct_UDT
286{
287 nothrow_construct_UDT()throw();
288 nothrow_construct_UDT(const nothrow_construct_UDT&);
289 ~nothrow_construct_UDT(){};
290 nothrow_construct_UDT& operator=(const nothrow_construct_UDT&){ return *this; }
291 bool operator==(const nothrow_construct_UDT&)const
292 { return true; }
293};
294
295class Base { };
296
297class Derived : public Base { };
298class Derived2 : public Base { };
299class MultiBase : public Derived, public Derived2 {};
300class PrivateBase : private Base {};
301
302class NonDerived { };
303
304enum enum1
305{
306 one_,two_
307};
308
309enum enum2
310{
311 three_,four_
312};
313
314struct VB
315{
316 virtual ~VB(){};
317};
318
319struct VD : public VB
320{
321 ~VD(){};
322};
323//
324// struct non_pointer:
325// used to verify that is_pointer does not return
326// true for class types that implement operator void*()
327//
328struct non_pointer
329{
330 operator void*(){return this;}
331};
332struct non_int_pointer
333{
334 int i;
335 operator int*(){return &i;}
336};
337struct int_constructible
338{
339 int_constructible(int);
340};
341struct int_convertible
342{
343 operator int();
344};
345//
346// struct non_empty:
347// used to verify that is_empty does not emit
348// spurious warnings or errors.
349//
350struct non_empty : private boost::noncopyable
351{
352 int i;
353};
354//
355// abstract base classes:
356struct test_abc1
357{
358 test_abc1();
359 virtual ~test_abc1();
360 test_abc1(const test_abc1&);
361 test_abc1& operator=(const test_abc1&);
362 virtual void foo() = 0;
363 virtual void foo2() = 0;
364};
365
366struct test_abc2
367{
368 virtual ~test_abc2();
369 virtual void foo() = 0;
370 virtual void foo2() = 0;
371};
372
373struct test_abc3 : public test_abc1
374{
375 virtual void foo3() = 0;
376};
377
378struct incomplete_type;
379
380struct polymorphic_base
381{
382 virtual ~polymorphic_base();
383 virtual void method();
384};
385
386struct polymorphic_derived1 : public polymorphic_base
387{
388};
389
390struct polymorphic_derived2 : public polymorphic_base
391{
392 virtual void method();
393};
394
395#ifndef BOOST_NO_CXX11_FINAL
396struct final_UDT final
397{};
398struct polymorphic_derived_final final : public polymorphic_derived2
399{};
400#endif
401
402
403struct virtual_inherit1 : public virtual Base { };
404struct virtual_inherit2 : public virtual_inherit1 { };
405struct virtual_inherit3 : private virtual Base {};
406struct virtual_inherit4 : public virtual boost::noncopyable {};
407struct virtual_inherit5 : public virtual int_convertible {};
408struct virtual_inherit6 : public virtual Base { virtual ~virtual_inherit6()throw(); };
409
410typedef void foo0_t();
411typedef void foo1_t(int);
412typedef void foo2_t(int&, double);
413typedef void foo3_t(int&, bool, int, int);
414typedef void foo4_t(int, bool, int*, int[], int, int, int, int, int);
415
416struct trivial_except_construct
417{
418 trivial_except_construct();
419 int i;
420};
421
422struct trivial_except_destroy
423{
424 ~trivial_except_destroy();
425 int i;
426};
427
428struct trivial_except_copy
429{
430 trivial_except_copy(trivial_except_copy const&);
431 int i;
432};
433
434struct trivial_except_assign
435{
436 trivial_except_assign& operator=(trivial_except_assign const&);
437 int i;
438};
439
440template <class T>
441struct wrap
442{
443 T t;
444 int j;
445protected:
446 wrap();
447 wrap(const wrap&);
448 wrap& operator=(const wrap&);
449};
450
451#ifdef BOOST_INTEL
452#pragma warning(pop)
453#endif
454
455#endif
456