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, typename... Types>
73 test_property(typename Property<Types...>::value_type value)
76 ret &= Property<Types...>::value == value;
77 ret &= Property<Types...>::type::value == value;
82 template<template<typename, typename> class Relationship,
83 typename Type1, typename Type2>
85 test_relationship(bool value)
88 ret &= Relationship<Type1, Type2>::value == value;
89 ret &= Relationship<Type1, Type2>::type::value == value;
95 typedef const ClassType cClassType;
96 typedef volatile ClassType vClassType;
97 typedef const volatile ClassType cvClassType;
99 class DerivedType : public ClassType { };
101 enum EnumType { e0 };
104 { operator int() const; };
108 virtual void rotate(int) = 0;
111 class PolymorphicClass
113 virtual void rotate(int);
116 class DerivedPolymorphic : public PolymorphicClass { };
118 class VirtualDestructorClass
120 virtual ~VirtualDestructorClass();
125 class IncompleteClass;
129 ExplicitClass(double&);
130 explicit ExplicitClass(int&);
131 ExplicitClass(double&, int&, double&);
134 struct NothrowExplicitClass
136 NothrowExplicitClass(double&) throw();
137 explicit NothrowExplicitClass(int&) throw();
138 NothrowExplicitClass(double&, int&, double&) throw();
141 struct ThrowExplicitClass
143 ThrowExplicitClass(double&) throw(int);
144 explicit ThrowExplicitClass(int&) throw(int);
145 ThrowExplicitClass(double&, int&, double&) throw(int);
148 struct ThrowDefaultClass
150 ThrowDefaultClass() throw(int);
153 struct ThrowCopyConsClass
155 ThrowCopyConsClass(const ThrowCopyConsClass&) throw(int);
158 #ifdef __GXX_EXPERIMENTAL_CXX0X__
159 struct ThrowMoveConsClass
161 ThrowMoveConsClass(ThrowMoveConsClass&&) throw(int);
164 struct NoexceptExplicitClass
166 NoexceptExplicitClass(double&) noexcept(true);
167 explicit NoexceptExplicitClass(int&) noexcept(true);
168 NoexceptExplicitClass(double&, int&, double&) noexcept(true);
171 struct ExceptExplicitClass
173 ExceptExplicitClass(double&) noexcept(false);
174 explicit ExceptExplicitClass(int&) noexcept(false);
175 ExceptExplicitClass(double&, int&, double&) noexcept(false);
178 struct NoexceptDefaultClass
180 NoexceptDefaultClass() noexcept(true);
183 struct ExceptDefaultClass
185 ExceptDefaultClass() noexcept(false);
188 struct NoexceptCopyConsClass
190 NoexceptCopyConsClass(const NoexceptCopyConsClass&) noexcept(true);
193 struct ExceptCopyConsClass
195 ExceptCopyConsClass(const ExceptCopyConsClass&) noexcept(false);
198 struct NoexceptMoveConsClass
200 NoexceptMoveConsClass(NoexceptMoveConsClass&&) noexcept(true);
203 struct ExceptMoveConsClass
205 ExceptMoveConsClass(ExceptMoveConsClass&&) noexcept(false);
208 struct NoexceptCopyAssignClass
210 NoexceptCopyAssignClass&
211 operator=(const NoexceptCopyAssignClass&) noexcept(true);
214 struct ExceptCopyAssignClass
216 ExceptCopyAssignClass&
217 operator=(const ExceptCopyAssignClass&) noexcept(false);
220 struct NoexceptMoveAssignClass
222 NoexceptMoveAssignClass&
223 operator=(NoexceptMoveAssignClass&&) noexcept(true);
226 struct ExceptMoveAssignClass
228 ExceptMoveAssignClass&
229 operator=(ExceptMoveAssignClass&&) noexcept(false);
232 struct DeletedCopyAssignClass
234 DeletedCopyAssignClass&
235 operator=(const DeletedCopyAssignClass&) = delete;
238 struct DeletedMoveAssignClass
240 DeletedMoveAssignClass&
241 operator=(DeletedMoveAssignClass&&) = delete;
244 struct NoexceptMoveConsNoexceptMoveAssignClass
246 NoexceptMoveConsNoexceptMoveAssignClass
247 (NoexceptMoveConsNoexceptMoveAssignClass&&) noexcept(true);
249 NoexceptMoveConsNoexceptMoveAssignClass&
250 operator=(NoexceptMoveConsNoexceptMoveAssignClass&&) noexcept(true);
253 struct ExceptMoveConsNoexceptMoveAssignClass
255 ExceptMoveConsNoexceptMoveAssignClass
256 (ExceptMoveConsNoexceptMoveAssignClass&&) noexcept(false);
258 ExceptMoveConsNoexceptMoveAssignClass&
259 operator=(ExceptMoveConsNoexceptMoveAssignClass&&) noexcept(true);
262 struct NoexceptMoveConsExceptMoveAssignClass
264 NoexceptMoveConsExceptMoveAssignClass
265 (NoexceptMoveConsExceptMoveAssignClass&&) noexcept(true);
267 NoexceptMoveConsExceptMoveAssignClass&
268 operator=(NoexceptMoveConsExceptMoveAssignClass&&) noexcept(false);
271 struct ExceptMoveConsExceptMoveAssignClass
273 ExceptMoveConsExceptMoveAssignClass
274 (ExceptMoveConsExceptMoveAssignClass&&) noexcept(false);
276 ExceptMoveConsExceptMoveAssignClass&
277 operator=(ExceptMoveConsExceptMoveAssignClass&&) noexcept(false);
281 struct NType // neither trivial nor standard-layout
288 struct TType // trivial but not standard-layout
295 struct SLType // standard-layout but not trivial
302 struct PODType // both trivial and standard-layout
308 #ifdef __GXX_EXPERIMENTAL_CXX0X__
309 struct LType // literal type
313 constexpr LType(int __i) : _M_i(__i) { }
316 struct LTypeDerived : public LType
318 constexpr LTypeDerived(int __i) : LType(__i) { }
321 struct NLType // not literal type
325 NLType() : _M_i(0) { }
327 constexpr NLType(int __i) : _M_i(__i) { }
329 NLType(const NLType& __other) : _M_i(__other._M_i) { }
331 ~NLType() { _M_i = 0; }
335 int truncate_float(float x) { return (int)x; }
336 long truncate_double(double x) { return (long)x; }
338 struct do_truncate_float_t
340 do_truncate_float_t()
345 do_truncate_float_t(const do_truncate_float_t&)
350 ~do_truncate_float_t()
355 int operator()(float x) { return (int)x; }
357 static int live_objects;
360 int do_truncate_float_t::live_objects = 0;
362 struct do_truncate_double_t
364 do_truncate_double_t()
369 do_truncate_double_t(const do_truncate_double_t&)
374 ~do_truncate_double_t()
379 long operator()(double x) { return (long)x; }
381 static int live_objects;
384 int do_truncate_double_t::live_objects = 0;
390 int foo() { return 1; }
391 int foo_c() const { return 2; }
392 int foo_v() volatile { return 3; }
393 int foo_cv() const volatile { return 4; }
396 // For use in 8_c_compatibility.
397 template<typename R, typename T>
398 typename __gnu_cxx::__enable_if<std::__are_same<R, T>::__value,
403 #ifdef __GXX_EXPERIMENTAL_CXX0X__
404 namespace construct_destruct
408 struct B { int i; B(){} };
413 enum class SE { e1 };
414 enum class SE2 { e2 };
417 enum class OpSE : bool;
419 union U { int i; Empty b; };
423 virtual ~Abstract() = 0;
426 struct AbstractDelDtor
428 ~AbstractDelDtor() = delete;
429 virtual void foo() = 0;
443 operator To() = delete;
449 explicit operator To();
459 DelEllipsis(...) = delete;
477 DelnAny(T&&...) = delete;
480 template<class... Args>
493 DelCopy(const DelCopy&) = delete;
499 DelDtor(const DelDtor&) = default;
500 DelDtor(DelDtor&&) = default;
509 Nontrivial(const Nontrivial&);
510 Nontrivial& operator=(const Nontrivial&);
514 union NontrivialUnion
522 UnusualCopy(UnusualCopy&);
530 struct B { int i; B(){} };
535 enum class SE { e1 };
536 enum class SE2 { e2 };
539 enum class OpSE : bool;
541 union U { int i; Empty b; };
556 void operator=(T&&) = delete;
561 virtual ~Abstract() = 0;
564 struct AbstractDelDtor
566 ~AbstractDelDtor() = delete;
567 virtual void foo() = 0;
581 explicit operator To();
587 operator To() = delete;
593 explicit operator To() = delete;
603 DelEllipsis(...) = delete;
621 DelnAny(T&&...) = delete;
624 template<class... Args>
630 template<class... Args>
633 DelFromArgs(Args...) = delete;
643 DelCopy(const DelCopy&) = delete;
649 DelDtor(const DelDtor&) = default;
650 DelDtor(DelDtor&&) = default;
659 Nontrivial(const Nontrivial&);
660 Nontrivial& operator=(const Nontrivial&);
664 union NontrivialUnion
672 UnusualCopy(UnusualCopy&);
684 void operator=(T&&) = delete;
689 DelCopyAssign& operator=(const DelCopyAssign&) = delete;
690 DelCopyAssign& operator=(DelCopyAssign&&) = default;
696 MO& operator=(MO&&) = default;
701 } // namespace __gnu_test
703 #endif // _GLIBCXX_TESTSUITE_TR1_H