]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/type_traits/test/test.hpp
import quincy beta 17.1.0
[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
20effc67 21#ifdef BOOST_BORLANDC
7c673cae
FG
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);
11fdf7f2
TL
180#if __cpp_noexcept_function_type
181 void f5()noexcept;
182 int f6(int)noexcept(true);
183 double f7()noexcept(false);
184#endif
7c673cae
FG
185};
186
187typedef void(*f1)();
188typedef int(*f2)(int);
189typedef int(*f3)(int, bool);
190typedef void (UDT::*mf1)();
191typedef int (UDT::*mf2)();
192typedef int (UDT::*mf3)(int);
193typedef int (UDT::*mf4)(int, float);
194typedef int (UDT::*mp);
195typedef int (UDT::*cmf)(int) const;
11fdf7f2
TL
196#if __cpp_noexcept_function_type
197typedef void (UDT::*mf5)()noexcept;
198typedef int (UDT::*mf6)(int)noexcept;
199typedef double (UDT::*mf7)()noexcept;
200#endif
201typedef int (UDT::*mf8)(...);
7c673cae
FG
202
203// cv-qualifiers applied to reference types should have no effect
204// declare these here for later use with is_reference and remove_reference:
205# ifdef BOOST_MSVC
206# pragma warning(push)
207# pragma warning(disable: 4181)
208# elif defined(BOOST_INTEL)
209# pragma warning(push)
210# pragma warning(disable: 21)
92f5a8d4
TL
211# elif defined(BOOST_CLANG)
212# pragma clang diagnostic push
213# pragma clang diagnostic ignored "-Wignored-qualifiers"
7c673cae
FG
214# endif
215//
216// This is intentional:
217// r_type and cr_type should be the same type
218// but some compilers wrongly apply cv-qualifiers
219// to reference types (this may generate a warning
220// on some compilers):
221//
222typedef int& r_type;
223#ifndef BOOST_INTEL
224typedef const r_type cr_type;
225#else
226// recent Intel compilers generate a hard error on the above:
227typedef r_type cr_type;
228#endif
229# ifdef BOOST_MSVC
230# pragma warning(pop)
231# elif defined(BOOST_INTEL)
232# pragma warning(pop)
233# pragma warning(disable: 985) // identifier truncated in debug information
92f5a8d4
TL
234# elif defined(BOOST_CLANG)
235# pragma clang diagnostic pop
7c673cae
FG
236# endif
237
238struct POD_UDT { int x; };
239struct empty_UDT
240{
241 empty_UDT();
242 empty_UDT(const empty_UDT&);
243 ~empty_UDT();
244 empty_UDT& operator=(const empty_UDT&);
245 bool operator==(const empty_UDT&)const;
246};
247struct empty_POD_UDT
248{
249 bool operator==(const empty_POD_UDT&)const
250 { return true; }
251};
252union union_UDT
253{
254 int x;
255 double y;
256 ~union_UDT(){}
257};
258union POD_union_UDT
259{
260 int x;
261 double y;
262};
263union empty_union_UDT
264{
265 ~empty_union_UDT(){}
266};
267union empty_POD_union_UDT{};
268
269struct nothrow_copy_UDT
270{
271 nothrow_copy_UDT();
272 nothrow_copy_UDT(const nothrow_copy_UDT&)throw();
273 ~nothrow_copy_UDT(){}
274 nothrow_copy_UDT& operator=(const nothrow_copy_UDT&);
275 bool operator==(const nothrow_copy_UDT&)const
276 { return true; }
277};
278
279struct nothrow_assign_UDT
280{
281 nothrow_assign_UDT();
282 nothrow_assign_UDT(const nothrow_assign_UDT&);
283 ~nothrow_assign_UDT(){};
284 nothrow_assign_UDT& operator=(const nothrow_assign_UDT&)throw(){ return *this; }
285 bool operator==(const nothrow_assign_UDT&)const
286 { return true; }
287};
288
289#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
290struct nothrow_move_UDT
291{
292 nothrow_move_UDT();
293 nothrow_move_UDT(nothrow_move_UDT&&) throw();
294 nothrow_move_UDT& operator=(nothrow_move_UDT&&) throw();
295 bool operator==(const nothrow_move_UDT&)const
296 { return true; }
297};
298#endif
299
300
301struct nothrow_construct_UDT
302{
303 nothrow_construct_UDT()throw();
304 nothrow_construct_UDT(const nothrow_construct_UDT&);
305 ~nothrow_construct_UDT(){};
306 nothrow_construct_UDT& operator=(const nothrow_construct_UDT&){ return *this; }
307 bool operator==(const nothrow_construct_UDT&)const
308 { return true; }
309};
310
311class Base { };
312
313class Derived : public Base { };
314class Derived2 : public Base { };
315class MultiBase : public Derived, public Derived2 {};
316class PrivateBase : private Base {};
317
318class NonDerived { };
319
320enum enum1
321{
322 one_,two_
323};
324
325enum enum2
326{
327 three_,four_
328};
329
92f5a8d4
TL
330#ifndef BOOST_NO_CXX11_SCOPED_ENUMS
331
332enum class scoped_enum { one, two, three };
333
334#endif
335
7c673cae
FG
336struct VB
337{
338 virtual ~VB(){};
339};
340
341struct VD : public VB
342{
343 ~VD(){};
344};
345//
346// struct non_pointer:
347// used to verify that is_pointer does not return
348// true for class types that implement operator void*()
349//
350struct non_pointer
351{
352 operator void*(){return this;}
353};
354struct non_int_pointer
355{
356 int i;
357 operator int*(){return &i;}
358};
359struct int_constructible
360{
361 int_constructible(int);
362};
363struct int_convertible
364{
365 operator int();
366};
367//
368// struct non_empty:
369// used to verify that is_empty does not emit
370// spurious warnings or errors.
371//
372struct non_empty : private boost::noncopyable
373{
374 int i;
375};
376//
377// abstract base classes:
378struct test_abc1
379{
380 test_abc1();
381 virtual ~test_abc1();
382 test_abc1(const test_abc1&);
383 test_abc1& operator=(const test_abc1&);
384 virtual void foo() = 0;
385 virtual void foo2() = 0;
386};
387
388struct test_abc2
389{
390 virtual ~test_abc2();
391 virtual void foo() = 0;
392 virtual void foo2() = 0;
393};
394
395struct test_abc3 : public test_abc1
396{
397 virtual void foo3() = 0;
398};
399
400struct incomplete_type;
401
402struct polymorphic_base
403{
404 virtual ~polymorphic_base();
405 virtual void method();
406};
407
408struct polymorphic_derived1 : public polymorphic_base
409{
410};
411
412struct polymorphic_derived2 : public polymorphic_base
413{
414 virtual void method();
415};
416
417#ifndef BOOST_NO_CXX11_FINAL
418struct final_UDT final
419{};
420struct polymorphic_derived_final final : public polymorphic_derived2
421{};
422#endif
423
424
425struct virtual_inherit1 : public virtual Base { };
426struct virtual_inherit2 : public virtual_inherit1 { };
427struct virtual_inherit3 : private virtual Base {};
428struct virtual_inherit4 : public virtual boost::noncopyable {};
429struct virtual_inherit5 : public virtual int_convertible {};
430struct virtual_inherit6 : public virtual Base { virtual ~virtual_inherit6()throw(); };
431
432typedef void foo0_t();
433typedef void foo1_t(int);
434typedef void foo2_t(int&, double);
435typedef void foo3_t(int&, bool, int, int);
436typedef void foo4_t(int, bool, int*, int[], int, int, int, int, int);
437
438struct trivial_except_construct
439{
440 trivial_except_construct();
441 int i;
442};
443
444struct trivial_except_destroy
445{
446 ~trivial_except_destroy();
447 int i;
448};
449
450struct trivial_except_copy
451{
452 trivial_except_copy(trivial_except_copy const&);
453 int i;
454};
455
456struct trivial_except_assign
457{
458 trivial_except_assign& operator=(trivial_except_assign const&);
459 int i;
460};
461
462template <class T>
463struct wrap
464{
465 T t;
466 int j;
467protected:
468 wrap();
469 wrap(const wrap&);
470 wrap& operator=(const wrap&);
471};
472
473#ifdef BOOST_INTEL
474#pragma warning(pop)
475#endif
476
477#endif
478