OSDN Git Service

2011-04-18 Paolo Carlini <paolo.carlini@oracle.com>
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / testsuite / util / testsuite_tr1.h
1 // -*- C++ -*-
2 // Testing utilities for the tr1 testsuite.
3 //
4 // Copyright (C) 2004, 2005, 2006, 2007, 2009, 2010, 2011
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.
12 //
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.
17 //
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/>.
21 //
22
23 #ifndef _GLIBCXX_TESTSUITE_TR1_H
24 #define _GLIBCXX_TESTSUITE_TR1_H
25
26 #include <ext/type_traits.h>
27
28 namespace __gnu_test
29 {
30   // For tr1/type_traits.
31   template<template<typename> class Category, typename Type>
32     bool
33     test_category(bool value)
34     {
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;
45     }
46
47   template<template<typename> class Property, typename Type>
48     bool
49     test_property(typename Property<Type>::value_type value)
50     {
51       bool ret = true;
52       ret &= Property<Type>::value == value;
53       ret &= Property<Type>::type::value == value;
54       return ret;
55     }
56
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)
63     {
64       bool ret = true;
65       ret &= Property<Type, Uint>::value == value;
66       ret &= Property<Type, Uint>::type::value == value;
67       return ret;
68     }
69
70 #ifdef __GXX_EXPERIMENTAL_CXX0X__
71   template<template<typename...> class Property, typename... Types>
72     bool
73     test_property(typename Property<Types...>::value_type value)
74     {
75       bool ret = true;
76       ret &= Property<Types...>::value == value;
77       ret &= Property<Types...>::type::value == value;
78       return ret;
79     }
80 #endif
81
82   template<template<typename, typename> class Relationship,
83            typename Type1, typename Type2>
84     bool
85     test_relationship(bool value)
86     {
87       bool ret = true;
88       ret &= Relationship<Type1, Type2>::value == value;
89       ret &= Relationship<Type1, Type2>::type::value == value;
90       return ret;
91     }
92
93   // Test types.
94   class ClassType { };
95   typedef const ClassType           cClassType;
96   typedef volatile ClassType        vClassType;
97   typedef const volatile ClassType  cvClassType;
98
99   class DerivedType : public ClassType { };
100
101   enum EnumType { e0 };
102
103   struct ConvType
104   { operator int() const; };
105
106   class AbstractClass
107   {
108     virtual void rotate(int) = 0;
109   };
110
111   class PolymorphicClass
112   {
113     virtual void rotate(int);
114   };
115
116   class DerivedPolymorphic : public PolymorphicClass { };
117
118   class VirtualDestructorClass
119   {
120     virtual ~VirtualDestructorClass();
121   };
122
123   union UnionType { };
124
125   class IncompleteClass;
126
127   struct ExplicitClass
128   {
129     ExplicitClass(double&);
130     explicit ExplicitClass(int&);
131     ExplicitClass(double&, int&, double&);
132   };
133
134   struct NothrowExplicitClass
135   {
136     NothrowExplicitClass(double&) throw();
137     explicit NothrowExplicitClass(int&) throw();
138     NothrowExplicitClass(double&, int&, double&) throw();
139   };
140
141   struct ThrowExplicitClass
142   {
143     ThrowExplicitClass(double&) throw(int);
144     explicit ThrowExplicitClass(int&) throw(int);
145     ThrowExplicitClass(double&, int&, double&) throw(int);
146   };
147
148   struct ThrowDefaultClass
149   {
150     ThrowDefaultClass() throw(int);
151   };
152
153   struct ThrowCopyConsClass
154   {
155     ThrowCopyConsClass(const ThrowCopyConsClass&) throw(int);
156   };
157
158 #ifdef __GXX_EXPERIMENTAL_CXX0X__
159   struct ThrowMoveConsClass
160   {
161     ThrowMoveConsClass(ThrowMoveConsClass&&) throw(int);
162   };
163
164   struct NoexceptExplicitClass
165   {
166     NoexceptExplicitClass(double&) noexcept(true);
167     explicit NoexceptExplicitClass(int&) noexcept(true);
168     NoexceptExplicitClass(double&, int&, double&) noexcept(true);
169   };
170
171   struct ExceptExplicitClass
172   {
173     ExceptExplicitClass(double&) noexcept(false);
174     explicit ExceptExplicitClass(int&) noexcept(false);
175     ExceptExplicitClass(double&, int&, double&) noexcept(false);
176   };
177
178   struct NoexceptDefaultClass
179   {
180     NoexceptDefaultClass() noexcept(true);
181   };
182
183   struct ExceptDefaultClass
184   {
185     ExceptDefaultClass() noexcept(false);
186   };
187
188   struct NoexceptCopyConsClass
189   {
190     NoexceptCopyConsClass(const NoexceptCopyConsClass&) noexcept(true);
191   };
192
193   struct ExceptCopyConsClass
194   {
195     ExceptCopyConsClass(const ExceptCopyConsClass&) noexcept(false);
196   };
197
198   struct NoexceptMoveConsClass
199   {
200     NoexceptMoveConsClass(NoexceptMoveConsClass&&) noexcept(true);
201   };
202
203   struct ExceptMoveConsClass
204   {
205     ExceptMoveConsClass(ExceptMoveConsClass&&) noexcept(false);
206   };
207 #endif
208
209   struct NType   // neither trivial nor standard-layout
210   {
211     int i;
212     int j;
213     virtual ~NType();
214   };
215
216   struct TType   // trivial but not standard-layout
217   {
218     int i;
219   private:
220     int j;
221   };
222
223   struct SLType  // standard-layout but not trivial
224   {
225     int i;
226     int j;
227     ~SLType();
228   };
229
230   struct PODType // both trivial and standard-layout
231   {
232     int i;
233     int j;
234   };
235
236 #ifdef __GXX_EXPERIMENTAL_CXX0X__
237   struct LType // literal type
238   {
239     int _M_i;
240
241     constexpr LType(int __i) : _M_i(__i) { }
242   };
243
244   struct LTypeDerived : public LType
245   {
246     constexpr LTypeDerived(int __i) : LType(__i) { }
247   };
248
249   struct NLType // not literal type
250   {
251     int _M_i;
252
253     NLType() : _M_i(0) { }
254
255     constexpr NLType(int __i) : _M_i(__i) { }
256
257     NLType(const NLType& __other) : _M_i(__other._M_i) { }
258
259     ~NLType() { _M_i = 0; }
260   };
261 #endif
262
263   int truncate_float(float x) { return (int)x; }
264   long truncate_double(double x) { return (long)x; }
265
266   struct do_truncate_float_t
267   {
268     do_truncate_float_t()
269     {
270       ++live_objects;
271     }
272
273     do_truncate_float_t(const do_truncate_float_t&)
274     {
275       ++live_objects;
276     }
277
278     ~do_truncate_float_t()
279     {
280       --live_objects;
281     }
282
283     int operator()(float x) { return (int)x; }
284
285     static int live_objects;
286   };
287
288   int do_truncate_float_t::live_objects = 0;
289
290   struct do_truncate_double_t
291   {
292     do_truncate_double_t()
293     {
294      ++live_objects;
295     }
296
297     do_truncate_double_t(const do_truncate_double_t&)
298     {
299       ++live_objects;
300     }
301
302     ~do_truncate_double_t()
303     {
304       --live_objects;
305     }
306
307     long operator()(double x) { return (long)x; }
308
309     static int live_objects;
310   };
311
312   int do_truncate_double_t::live_objects = 0;
313
314   struct X
315   {
316     int bar;
317
318     int foo()                   { return 1; }
319     int foo_c() const           { return 2; }
320     int foo_v()  volatile       { return 3; }
321     int foo_cv() const volatile { return 4; }
322   };
323
324   // For use in 8_c_compatibility.
325   template<typename R, typename T>
326     typename __gnu_cxx::__enable_if<std::__are_same<R, T>::__value,
327                                     bool>::__type
328     check_ret_type(T)
329     { return true; }
330
331 #ifdef __GXX_EXPERIMENTAL_CXX0X__
332   namespace construct_destruct
333   {
334     struct Empty {};
335
336     struct B { int i; B(){} };
337     struct D : B {};
338
339     enum E { ee1 };
340     enum E2 { ee2 };
341     enum class SE { e1 };
342     enum class SE2 { e2 };
343
344     enum OpE : int;
345     enum class OpSE : bool;
346
347     union U { int i; Empty b; };
348
349     struct Abstract
350     {
351       virtual ~Abstract() = 0;
352     };
353
354     struct AbstractDelDtor
355     {
356       ~AbstractDelDtor() = delete;
357       virtual void foo() = 0;
358     };
359
360     struct Ukn;
361
362     template<class To>
363       struct ImplicitTo
364       {
365         operator To();
366       };
367
368     template<class To>
369       struct DelImplicitTo
370       {
371         operator To() = delete;
372       };
373
374     template<class To>
375       struct ExplicitTo
376       {
377         explicit operator To();
378       };
379
380     struct Ellipsis
381     {
382       Ellipsis(...){}
383     };
384
385     struct DelEllipsis
386     {
387       DelEllipsis(...) = delete;
388     };
389
390     struct Any
391     {
392       template<class T>
393       Any(T&&){}
394     };
395
396     struct nAny
397     {
398       template<class... T>
399       nAny(T&&...){}
400     };
401
402     struct DelnAny
403     {
404       template<class... T>
405         DelnAny(T&&...) = delete;
406     };
407
408     template<class... Args>
409       struct FromArgs
410       {
411         FromArgs(Args...);
412       };
413
414     struct DelDef
415     {
416       DelDef() = delete;
417     };
418
419     struct DelCopy
420     {
421       DelCopy(const DelCopy&) = delete;
422     };
423
424     struct DelDtor
425     {
426       DelDtor() = default;
427       DelDtor(const DelDtor&) = default;
428       DelDtor(DelDtor&&) = default;
429       DelDtor(int);
430       DelDtor(int, B, U);
431       ~DelDtor() = delete;
432     };
433
434     struct Nontrivial
435     {
436       Nontrivial();
437       Nontrivial(const Nontrivial&);
438       Nontrivial& operator=(const Nontrivial&);
439       ~Nontrivial();
440     };
441
442     union NontrivialUnion
443     {
444       int i;
445       Nontrivial n;
446     };
447
448     struct UnusualCopy
449     {
450       UnusualCopy(UnusualCopy&);
451     };
452   }
453 #endif
454
455 } // namespace __gnu_test
456
457 #endif // _GLIBCXX_TESTSUITE_TR1_H