OSDN Git Service

2011-05-19 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
208   struct NoexceptCopyAssignClass
209   {
210     NoexceptCopyAssignClass&
211     operator=(const NoexceptCopyAssignClass&) noexcept(true);
212   };
213
214   struct ExceptCopyAssignClass
215   {
216     ExceptCopyAssignClass&
217     operator=(const ExceptCopyAssignClass&) noexcept(false);
218   };
219
220   struct NoexceptMoveAssignClass
221   {
222     NoexceptMoveAssignClass&
223     operator=(NoexceptMoveAssignClass&&) noexcept(true);
224   };
225
226   struct ExceptMoveAssignClass
227   {
228     ExceptMoveAssignClass&
229     operator=(ExceptMoveAssignClass&&) noexcept(false);
230   };
231
232   struct DeletedCopyAssignClass
233   {
234     DeletedCopyAssignClass&
235     operator=(const DeletedCopyAssignClass&) = delete;
236   };
237
238   struct DeletedMoveAssignClass
239   {
240     DeletedMoveAssignClass&
241     operator=(DeletedMoveAssignClass&&) = delete;
242   };
243
244   struct NoexceptMoveConsNoexceptMoveAssignClass
245   {
246     NoexceptMoveConsNoexceptMoveAssignClass
247     (NoexceptMoveConsNoexceptMoveAssignClass&&) noexcept(true);
248
249     NoexceptMoveConsNoexceptMoveAssignClass&
250     operator=(NoexceptMoveConsNoexceptMoveAssignClass&&) noexcept(true);
251   };
252
253   struct ExceptMoveConsNoexceptMoveAssignClass
254   {
255     ExceptMoveConsNoexceptMoveAssignClass
256     (ExceptMoveConsNoexceptMoveAssignClass&&) noexcept(false);
257
258     ExceptMoveConsNoexceptMoveAssignClass&
259     operator=(ExceptMoveConsNoexceptMoveAssignClass&&) noexcept(true);
260   };
261
262   struct NoexceptMoveConsExceptMoveAssignClass
263   {
264     NoexceptMoveConsExceptMoveAssignClass
265     (NoexceptMoveConsExceptMoveAssignClass&&) noexcept(true);
266
267     NoexceptMoveConsExceptMoveAssignClass&
268     operator=(NoexceptMoveConsExceptMoveAssignClass&&) noexcept(false);
269   };
270
271   struct ExceptMoveConsExceptMoveAssignClass
272   {
273     ExceptMoveConsExceptMoveAssignClass
274     (ExceptMoveConsExceptMoveAssignClass&&) noexcept(false);
275
276     ExceptMoveConsExceptMoveAssignClass&
277     operator=(ExceptMoveConsExceptMoveAssignClass&&) noexcept(false);
278   };
279 #endif
280
281   struct NType   // neither trivial nor standard-layout
282   {
283     int i;
284     int j;
285     virtual ~NType();
286   };
287
288   struct TType   // trivial but not standard-layout
289   {
290     int i;
291   private:
292     int j;
293   };
294
295   struct SLType  // standard-layout but not trivial
296   {
297     int i;
298     int j;
299     ~SLType();
300   };
301
302   struct PODType // both trivial and standard-layout
303   {
304     int i;
305     int j;
306   };
307
308 #ifdef __GXX_EXPERIMENTAL_CXX0X__
309   struct LType // literal type
310   {
311     int _M_i;
312
313     constexpr LType(int __i) : _M_i(__i) { }
314   };
315
316   struct LTypeDerived : public LType
317   {
318     constexpr LTypeDerived(int __i) : LType(__i) { }
319   };
320
321   struct NLType // not literal type
322   {
323     int _M_i;
324
325     NLType() : _M_i(0) { }
326
327     constexpr NLType(int __i) : _M_i(__i) { }
328
329     NLType(const NLType& __other) : _M_i(__other._M_i) { }
330
331     ~NLType() { _M_i = 0; }
332   };
333 #endif
334
335   int truncate_float(float x) { return (int)x; }
336   long truncate_double(double x) { return (long)x; }
337
338   struct do_truncate_float_t
339   {
340     do_truncate_float_t()
341     {
342       ++live_objects;
343     }
344
345     do_truncate_float_t(const do_truncate_float_t&)
346     {
347       ++live_objects;
348     }
349
350     ~do_truncate_float_t()
351     {
352       --live_objects;
353     }
354
355     int operator()(float x) { return (int)x; }
356
357     static int live_objects;
358   };
359
360   int do_truncate_float_t::live_objects = 0;
361
362   struct do_truncate_double_t
363   {
364     do_truncate_double_t()
365     {
366      ++live_objects;
367     }
368
369     do_truncate_double_t(const do_truncate_double_t&)
370     {
371       ++live_objects;
372     }
373
374     ~do_truncate_double_t()
375     {
376       --live_objects;
377     }
378
379     long operator()(double x) { return (long)x; }
380
381     static int live_objects;
382   };
383
384   int do_truncate_double_t::live_objects = 0;
385
386   struct X
387   {
388     int bar;
389
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; }
394   };
395
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,
399                                     bool>::__type
400     check_ret_type(T)
401     { return true; }
402
403 #ifdef __GXX_EXPERIMENTAL_CXX0X__
404   namespace construct_destruct
405   {
406     struct Empty {};
407
408     struct B { int i; B(){} };
409     struct D : B {};
410
411     enum E { ee1 };
412     enum E2 { ee2 };
413     enum class SE { e1 };
414     enum class SE2 { e2 };
415
416     enum OpE : int;
417     enum class OpSE : bool;
418
419     union U { int i; Empty b; };
420
421     struct Abstract
422     {
423       virtual ~Abstract() = 0;
424     };
425
426     struct AbstractDelDtor
427     {
428       ~AbstractDelDtor() = delete;
429       virtual void foo() = 0;
430     };
431
432     struct Ukn;
433
434     template<class To>
435       struct ImplicitTo
436       {
437         operator To();
438       };
439
440     template<class To>
441       struct DelImplicitTo
442       {
443         operator To() = delete;
444       };
445
446     template<class To>
447       struct ExplicitTo
448       {
449         explicit operator To();
450       };
451
452     struct Ellipsis
453     {
454       Ellipsis(...){}
455     };
456
457     struct DelEllipsis
458     {
459       DelEllipsis(...) = delete;
460     };
461
462     struct Any
463     {
464       template<class T>
465       Any(T&&){}
466     };
467
468     struct nAny
469     {
470       template<class... T>
471       nAny(T&&...){}
472     };
473
474     struct DelnAny
475     {
476       template<class... T>
477         DelnAny(T&&...) = delete;
478     };
479
480     template<class... Args>
481       struct FromArgs
482       {
483         FromArgs(Args...);
484       };
485
486     struct DelDef
487     {
488       DelDef() = delete;
489     };
490
491     struct DelCopy
492     {
493       DelCopy(const DelCopy&) = delete;
494     };
495
496     struct DelDtor
497     {
498       DelDtor() = default;
499       DelDtor(const DelDtor&) = default;
500       DelDtor(DelDtor&&) = default;
501       DelDtor(int);
502       DelDtor(int, B, U);
503       ~DelDtor() = delete;
504     };
505
506     struct Nontrivial
507     {
508       Nontrivial();
509       Nontrivial(const Nontrivial&);
510       Nontrivial& operator=(const Nontrivial&);
511       ~Nontrivial();
512     };
513
514     union NontrivialUnion
515     {
516       int i;
517       Nontrivial n;
518     };
519
520     struct UnusualCopy
521     {
522       UnusualCopy(UnusualCopy&);
523     };
524   }
525
526   namespace assign
527   {
528     struct Empty {};
529
530     struct B { int i; B(){} };
531     struct D : B {};
532
533     enum E { ee1 };
534     enum E2 { ee2 };
535     enum class SE { e1 };
536     enum class SE2 { e2 };
537
538     enum OpE : int;
539     enum class OpSE : bool;
540
541     union U { int i; Empty b; };
542
543     union UAssignAll
544     {
545       bool b;
546       char c;
547       template<class T>
548       void operator=(T&&);
549     };
550
551     union UDelAssignAll
552     {
553       bool b;
554       char c;
555       template<class T>
556       void operator=(T&&) = delete;
557     };
558
559     struct Abstract
560     {
561       virtual ~Abstract() = 0;
562     };
563
564     struct AbstractDelDtor
565     {
566       ~AbstractDelDtor() = delete;
567       virtual void foo() = 0;
568     };
569
570     struct Ukn;
571
572     template<class To>
573       struct ImplicitTo
574       {
575         operator To();
576       };
577
578     template<class To>
579       struct ExplicitTo
580       {
581         explicit operator To();
582       };
583
584     template<class To>
585       struct DelImplicitTo
586       {
587         operator To() = delete;
588       };
589
590     template<class To>
591       struct DelExplicitTo
592       {
593         explicit operator To() = delete;
594       };
595
596     struct Ellipsis
597     {
598       Ellipsis(...){}
599     };
600
601     struct DelEllipsis
602     {
603       DelEllipsis(...) = delete;
604     };
605
606     struct Any
607     {
608       template<class T>
609         Any(T&&){}
610     };
611
612     struct nAny
613     {
614       template<class... T>
615         nAny(T&&...){}
616     };
617
618     struct DelnAny
619     {
620       template<class... T>
621         DelnAny(T&&...) = delete;
622     };
623
624     template<class... Args>
625       struct FromArgs
626       {
627         FromArgs(Args...);
628       };
629
630     template<class... Args>
631       struct DelFromArgs
632       {
633         DelFromArgs(Args...) = delete;
634       };
635
636     struct DelDef
637     {
638       DelDef() = delete;
639     };
640
641     struct DelCopy
642     {
643       DelCopy(const DelCopy&) = delete;
644     };
645
646     struct DelDtor
647     {
648       DelDtor() = default;
649       DelDtor(const DelDtor&) = default;
650       DelDtor(DelDtor&&) = default;
651       DelDtor(int);
652       DelDtor(int, B, U);
653       ~DelDtor() = delete;
654     };
655
656     struct Nontrivial
657     {
658       Nontrivial();
659       Nontrivial(const Nontrivial&);
660       Nontrivial& operator=(const Nontrivial&);
661       ~Nontrivial();
662     };
663
664     union NontrivialUnion
665     {
666       int i;
667       Nontrivial n;
668     };
669
670     struct UnusualCopy
671     {
672       UnusualCopy(UnusualCopy&);
673     };
674
675     struct AnyAssign
676     {
677       template<class T>
678         void operator=(T&&);
679     };
680
681     struct DelAnyAssign
682     {
683       template<class T>
684         void operator=(T&&) = delete;
685     };
686
687     struct DelCopyAssign
688     {
689       DelCopyAssign& operator=(const DelCopyAssign&) = delete;
690       DelCopyAssign& operator=(DelCopyAssign&&) = default;
691     };
692
693     struct MO
694     {
695       MO(MO&&) = default;
696       MO& operator=(MO&&) = default;
697     };
698   }
699 #endif
700
701 } // namespace __gnu_test
702
703 #endif // _GLIBCXX_TESTSUITE_TR1_H