Merged trunk at revision 161680 into branch.
[official-gcc.git] / libstdc++-v3 / testsuite / util / testsuite_tr1.h
blob5aac18292bb0f296e164a0bc1bc11e8621c60949
1 // -*- C++ -*-
2 // Testing utilities for the tr1 testsuite.
3 //
4 // Copyright (C) 2004, 2005, 2006, 2007, 2009, 2010
5 // Free Software Foundation, Inc.
6 //
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)
11 // any later version.
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>
28 namespace __gnu_test
30 // For tr1/type_traits.
31 template<template<typename> class Category, typename Type>
32 bool
33 test_category(bool value)
35 bool ret = true;
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;
44 return ret;
47 template<template<typename> class Property, typename Type>
48 bool
49 test_property(typename Property<Type>::value_type value)
51 bool ret = true;
52 ret &= Property<Type>::value == value;
53 ret &= Property<Type>::type::value == value;
54 return ret;
57 // For testing tr1/type_traits/extent, which has a second template
58 // parameter.
59 template<template<typename, unsigned> class Property,
60 typename Type, unsigned Uint>
61 bool
62 test_property(typename Property<Type, Uint>::value_type value)
64 bool ret = true;
65 ret &= Property<Type, Uint>::value == value;
66 ret &= Property<Type, Uint>::type::value == value;
67 return ret;
70 #ifdef __GXX_EXPERIMENTAL_CXX0X__
71 template<template<typename...> class Property, typename... Types>
72 bool
73 test_property(typename Property<Types...>::value_type value)
75 bool ret = true;
76 ret &= Property<Types...>::value == value;
77 ret &= Property<Types...>::type::value == value;
78 return ret;
80 #endif
82 template<template<typename, typename> class Relationship,
83 typename Type1, typename Type2>
84 bool
85 test_relationship(bool value)
87 bool ret = true;
88 ret &= Relationship<Type1, Type2>::value == value;
89 ret &= Relationship<Type1, Type2>::type::value == value;
90 return ret;
93 // Test types.
94 class ClassType { };
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 };
103 struct ConvType
104 { operator int() const; };
106 class AbstractClass
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();
123 union UnionType { };
125 class IncompleteClass;
127 struct ExplicitClass
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 #ifdef __GXX_EXPERIMENTAL_CXX0X__
149 struct NoexceptExplicitClass
151 NoexceptExplicitClass(double&) noexcept(true);
152 explicit NoexceptExplicitClass(int&) noexcept(true);
153 NoexceptExplicitClass(double&, int&, double&) noexcept(true);
156 struct ExceptExplicitClass
158 ExceptExplicitClass(double&) noexcept(false);
159 explicit ExceptExplicitClass(int&) noexcept(false);
160 ExceptExplicitClass(double&, int&, double&) noexcept(false);
162 #endif
164 struct NType // neither trivial nor standard-layout
166 int i;
167 int j;
168 virtual ~NType();
171 struct TType // trivial but not standard-layout
173 int i;
174 private:
175 int j;
178 struct SLType // standard-layout but not trivial
180 int i;
181 int j;
182 ~SLType();
185 struct PODType // both trivial and standard-layout
187 int i;
188 int j;
191 int truncate_float(float x) { return (int)x; }
192 long truncate_double(double x) { return (long)x; }
194 struct do_truncate_float_t
196 do_truncate_float_t()
198 ++live_objects;
201 do_truncate_float_t(const do_truncate_float_t&)
203 ++live_objects;
206 ~do_truncate_float_t()
208 --live_objects;
211 int operator()(float x) { return (int)x; }
213 static int live_objects;
216 int do_truncate_float_t::live_objects = 0;
218 struct do_truncate_double_t
220 do_truncate_double_t()
222 ++live_objects;
225 do_truncate_double_t(const do_truncate_double_t&)
227 ++live_objects;
230 ~do_truncate_double_t()
232 --live_objects;
235 long operator()(double x) { return (long)x; }
237 static int live_objects;
240 int do_truncate_double_t::live_objects = 0;
242 struct X
244 int bar;
246 int foo() { return 1; }
247 int foo_c() const { return 2; }
248 int foo_v() volatile { return 3; }
249 int foo_cv() const volatile { return 4; }
252 // For use in 8_c_compatibility.
253 template<typename R, typename T>
254 typename __gnu_cxx::__enable_if<std::__are_same<R, T>::__value,
255 bool>::__type
256 check_ret_type(T)
257 { return true; }
259 } // namespace __gnu_test
261 #endif // _GLIBCXX_TESTSUITE_TR1_H