2 // Testing utilities for the tr1 testsuite.
4 // Copyright (C) 2004, 2005, 2006, 2007, 2009, 2010, 2011
5 // Free Software Foundation, Inc.
7 // This file is part of the GNU ISO C++ Library. This library is free
8 // software; you can redistribute it and/or modify it under the
9 // terms of the GNU General Public License as published by the
10 // Free Software Foundation; either version 3, or (at your option)
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License along
19 // with this library; see the file COPYING3. If not see
20 // <http://www.gnu.org/licenses/>.
23 #ifndef _GLIBCXX_TESTSUITE_TR1_H
24 #define _GLIBCXX_TESTSUITE_TR1_H
26 #include <ext/type_traits.h>
30 // For tr1/type_traits.
31 template<template<typename> class Category, typename Type>
33 test_category(bool value)
36 ret &= Category<Type>::value == value;
37 ret &= Category<const Type>::value == value;
38 ret &= Category<volatile Type>::value == value;
39 ret &= Category<const volatile Type>::value == value;
40 ret &= Category<Type>::type::value == value;
41 ret &= Category<const Type>::type::value == value;
42 ret &= Category<volatile Type>::type::value == value;
43 ret &= Category<const volatile Type>::type::value == value;
47 template<template<typename> class Property, typename Type>
49 test_property(typename Property<Type>::value_type value)
52 ret &= Property<Type>::value == value;
53 ret &= Property<Type>::type::value == value;
57 // For testing tr1/type_traits/extent, which has a second template
59 template<template<typename, unsigned> class Property,
60 typename Type, unsigned Uint>
62 test_property(typename Property<Type, Uint>::value_type value)
65 ret &= Property<Type, Uint>::value == value;
66 ret &= Property<Type, Uint>::type::value == value;
70 #ifdef __GXX_EXPERIMENTAL_CXX0X__
71 template<template<typename...> class Property,
72 typename Type1, typename... Types>
74 test_property(typename Property<Type1, Types...>::value_type value)
77 ret &= Property<Type1, Types...>::value == value;
78 ret &= Property<Type1, Types...>::type::value == value;
83 template<template<typename, typename> class Relationship,
84 typename Type1, typename Type2>
86 test_relationship(bool value)
89 ret &= Relationship<Type1, Type2>::value == value;
90 ret &= Relationship<Type1, Type2>::type::value == value;
96 typedef const ClassType cClassType;
97 typedef volatile ClassType vClassType;
98 typedef const volatile ClassType cvClassType;
100 class DerivedType : public ClassType { };
102 enum EnumType { e0 };
105 { operator int() const; };
109 virtual void rotate(int) = 0;
112 class PolymorphicClass
114 virtual void rotate(int);
117 class DerivedPolymorphic : public PolymorphicClass { };
119 class VirtualDestructorClass
121 virtual ~VirtualDestructorClass();
126 class IncompleteClass;
130 ExplicitClass(double&);
131 explicit ExplicitClass(int&);
132 ExplicitClass(double&, int&, double&);
135 struct NothrowExplicitClass
137 NothrowExplicitClass(double&) throw();
138 explicit NothrowExplicitClass(int&) throw();
139 NothrowExplicitClass(double&, int&, double&) throw();
142 struct ThrowExplicitClass
144 ThrowExplicitClass(double&) throw(int);
145 explicit ThrowExplicitClass(int&) throw(int);
146 ThrowExplicitClass(double&, int&, double&) throw(int);
149 struct ThrowDefaultClass
151 ThrowDefaultClass() throw(int);
154 struct ThrowCopyConsClass
156 ThrowCopyConsClass(const ThrowCopyConsClass&) throw(int);
159 #ifdef __GXX_EXPERIMENTAL_CXX0X__
160 struct ThrowMoveConsClass
162 ThrowMoveConsClass(ThrowMoveConsClass&&) throw(int);
165 struct NoexceptExplicitClass
167 NoexceptExplicitClass(double&) noexcept(true);
168 explicit NoexceptExplicitClass(int&) noexcept(true);
169 NoexceptExplicitClass(double&, int&, double&) noexcept(true);
172 struct ExceptExplicitClass
174 ExceptExplicitClass(double&) noexcept(false);
175 explicit ExceptExplicitClass(int&) noexcept(false);
176 ExceptExplicitClass(double&, int&, double&) noexcept(false);
179 struct NoexceptDefaultClass
181 NoexceptDefaultClass() noexcept(true);
184 struct ExceptDefaultClass
186 ExceptDefaultClass() noexcept(false);
189 struct NoexceptCopyConsClass
191 NoexceptCopyConsClass(const NoexceptCopyConsClass&) noexcept(true);
194 struct ExceptCopyConsClass
196 ExceptCopyConsClass(const ExceptCopyConsClass&) noexcept(false);
199 struct NoexceptMoveConsClass
201 NoexceptMoveConsClass(NoexceptMoveConsClass&&) noexcept(true);
204 struct ExceptMoveConsClass
206 ExceptMoveConsClass(ExceptMoveConsClass&&) noexcept(false);
209 struct NoexceptCopyAssignClass
211 NoexceptCopyAssignClass&
212 operator=(const NoexceptCopyAssignClass&) noexcept(true);
215 struct ExceptCopyAssignClass
217 ExceptCopyAssignClass&
218 operator=(const ExceptCopyAssignClass&) noexcept(false);
221 struct NoexceptMoveAssignClass
223 NoexceptMoveAssignClass&
224 operator=(NoexceptMoveAssignClass&&) noexcept(true);
227 struct ExceptMoveAssignClass
229 ExceptMoveAssignClass&
230 operator=(ExceptMoveAssignClass&&) noexcept(false);
233 struct DeletedCopyAssignClass
235 DeletedCopyAssignClass&
236 operator=(const DeletedCopyAssignClass&) = delete;
239 struct DeletedMoveAssignClass
241 DeletedMoveAssignClass&
242 operator=(DeletedMoveAssignClass&&) = delete;
245 struct NoexceptMoveConsNoexceptMoveAssignClass
247 NoexceptMoveConsNoexceptMoveAssignClass
248 (NoexceptMoveConsNoexceptMoveAssignClass&&) noexcept(true);
250 NoexceptMoveConsNoexceptMoveAssignClass&
251 operator=(NoexceptMoveConsNoexceptMoveAssignClass&&) noexcept(true);
254 struct ExceptMoveConsNoexceptMoveAssignClass
256 ExceptMoveConsNoexceptMoveAssignClass
257 (ExceptMoveConsNoexceptMoveAssignClass&&) noexcept(false);
259 ExceptMoveConsNoexceptMoveAssignClass&
260 operator=(ExceptMoveConsNoexceptMoveAssignClass&&) noexcept(true);
263 struct NoexceptMoveConsExceptMoveAssignClass
265 NoexceptMoveConsExceptMoveAssignClass
266 (NoexceptMoveConsExceptMoveAssignClass&&) noexcept(true);
268 NoexceptMoveConsExceptMoveAssignClass&
269 operator=(NoexceptMoveConsExceptMoveAssignClass&&) noexcept(false);
272 struct ExceptMoveConsExceptMoveAssignClass
274 ExceptMoveConsExceptMoveAssignClass
275 (ExceptMoveConsExceptMoveAssignClass&&) noexcept(false);
277 ExceptMoveConsExceptMoveAssignClass&
278 operator=(ExceptMoveConsExceptMoveAssignClass&&) noexcept(false);
282 struct NType // neither trivial nor standard-layout
289 struct TType // trivial but not standard-layout
296 struct SLType // standard-layout but not trivial
303 struct PODType // both trivial and standard-layout
309 #ifdef __GXX_EXPERIMENTAL_CXX0X__
310 struct LType // literal type
314 constexpr LType(int __i) : _M_i(__i) { }
317 struct LTypeDerived : public LType
319 constexpr LTypeDerived(int __i) : LType(__i) { }
322 struct NLType // not literal type
326 NLType() : _M_i(0) { }
328 constexpr NLType(int __i) : _M_i(__i) { }
330 NLType(const NLType& __other) : _M_i(__other._M_i) { }
332 ~NLType() { _M_i = 0; }
336 int truncate_float(float x) { return (int)x; }
337 long truncate_double(double x) { return (long)x; }
339 struct do_truncate_float_t
341 do_truncate_float_t()
346 do_truncate_float_t(const do_truncate_float_t&)
351 ~do_truncate_float_t()
356 int operator()(float x) { return (int)x; }
358 static int live_objects;
361 int do_truncate_float_t::live_objects = 0;
363 struct do_truncate_double_t
365 do_truncate_double_t()
370 do_truncate_double_t(const do_truncate_double_t&)
375 ~do_truncate_double_t()
380 long operator()(double x) { return (long)x; }
382 static int live_objects;
385 int do_truncate_double_t::live_objects = 0;
391 int foo() { return 1; }
392 int foo_c() const { return 2; }
393 int foo_v() volatile { return 3; }
394 int foo_cv() const volatile { return 4; }
397 // For use in 8_c_compatibility.
398 template<typename R, typename T>
399 typename __gnu_cxx::__enable_if<std::__are_same<R, T>::__value,
404 #ifdef __GXX_EXPERIMENTAL_CXX0X__
405 namespace construct_destruct
409 struct B { int i; B(){} };
414 enum class SE { e1 };
415 enum class SE2 { e2 };
418 enum class OpSE : bool;
420 union U { int i; Empty b; };
424 virtual ~Abstract() = 0;
427 struct AbstractDelDtor
429 ~AbstractDelDtor() = delete;
430 virtual void foo() = 0;
444 operator To() = delete;
450 explicit operator To();
460 DelEllipsis(...) = delete;
478 DelnAny(T&&...) = delete;
481 template<class... Args>
494 DelCopy(const DelCopy&) = delete;
500 DelDtor(const DelDtor&) = default;
501 DelDtor(DelDtor&&) = default;
510 Nontrivial(const Nontrivial&);
511 Nontrivial& operator=(const Nontrivial&);
515 union NontrivialUnion
523 UnusualCopy(UnusualCopy&);
531 struct B { int i; B(){} };
536 enum class SE { e1 };
537 enum class SE2 { e2 };
540 enum class OpSE : bool;
542 union U { int i; Empty b; };
557 void operator=(T&&) = delete;
562 virtual ~Abstract() = 0;
565 struct AbstractDelDtor
567 ~AbstractDelDtor() = delete;
568 virtual void foo() = 0;
582 explicit operator To();
588 operator To() = delete;
594 explicit operator To() = delete;
604 DelEllipsis(...) = delete;
622 DelnAny(T&&...) = delete;
625 template<class... Args>
631 template<class... Args>
634 DelFromArgs(Args...) = delete;
644 DelCopy(const DelCopy&) = delete;
650 DelDtor(const DelDtor&) = default;
651 DelDtor(DelDtor&&) = default;
660 Nontrivial(const Nontrivial&);
661 Nontrivial& operator=(const Nontrivial&);
665 union NontrivialUnion
673 UnusualCopy(UnusualCopy&);
685 void operator=(T&&) = delete;
690 DelCopyAssign& operator=(const DelCopyAssign&) = delete;
691 DelCopyAssign& operator=(DelCopyAssign&&) = default;
697 MO& operator=(MO&&) = default;
701 struct CopyConsOnlyType
703 CopyConsOnlyType(int) { }
704 CopyConsOnlyType(CopyConsOnlyType&&) = delete;
705 CopyConsOnlyType(const CopyConsOnlyType&) = default;
706 CopyConsOnlyType& operator=(const CopyConsOnlyType&) = delete;
707 CopyConsOnlyType& operator=(CopyConsOnlyType&&) = delete;
710 struct MoveConsOnlyType
712 MoveConsOnlyType(int) { }
713 MoveConsOnlyType(const MoveConsOnlyType&) = delete;
714 MoveConsOnlyType(MoveConsOnlyType&&) = default;
715 MoveConsOnlyType& operator=(const MoveConsOnlyType&) = delete;
716 MoveConsOnlyType& operator=(MoveConsOnlyType&&) = delete;
720 } // namespace __gnu_test
722 #endif // _GLIBCXX_TESTSUITE_TR1_H