]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/util/testsuite_tr1.h
value.cc: New.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / util / testsuite_tr1.h
CommitLineData
493bc460
PC
1// -*- C++ -*-
2// Testing utilities for the tr1 testsuite.
3//
748086b7 4// Copyright (C) 2004, 2005, 2006, 2007, 2009 Free Software Foundation, Inc.
493bc460
PC
5//
6// This file is part of the GNU ISO C++ Library. This library is free
7// software; you can redistribute it and/or modify it under the
8// terms of the GNU General Public License as published by the
748086b7 9// Free Software Foundation; either version 3, or (at your option)
493bc460
PC
10// any later version.
11//
12// This library is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15// GNU General Public License for more details.
16//
17// You should have received a copy of the GNU General Public License along
748086b7
JJ
18// with this library; see the file COPYING3. If not see
19// <http://www.gnu.org/licenses/>.
493bc460 20//
493bc460
PC
21
22#ifndef _GLIBCXX_TESTSUITE_TR1_H
23#define _GLIBCXX_TESTSUITE_TR1_H
24
105c6331 25#include <ext/type_traits.h>
ab44b018 26
493bc460 27namespace __gnu_test
0179f2c6 28{
493bc460 29 // For tr1/type_traits.
105c6331 30 template<template<typename> class Category, typename Type>
493bc460 31 bool
db5ff236 32 test_category(bool value)
493bc460
PC
33 {
34 bool ret = true;
db5ff236
PC
35 ret &= Category<Type>::value == value;
36 ret &= Category<const Type>::value == value;
37 ret &= Category<volatile Type>::value == value;
38 ret &= Category<const volatile Type>::value == value;
39 ret &= Category<Type>::type::value == value;
40 ret &= Category<const Type>::type::value == value;
41 ret &= Category<volatile Type>::type::value == value;
42 ret &= Category<const volatile Type>::type::value == value;
493bc460
PC
43 return ret;
44 }
0f910b4f 45
105c6331 46 template<template<typename> class Property, typename Type>
0f910b4f 47 bool
db5ff236 48 test_property(typename Property<Type>::value_type value)
0f910b4f
PC
49 {
50 bool ret = true;
db5ff236
PC
51 ret &= Property<Type>::value == value;
52 ret &= Property<Type>::type::value == value;
0f910b4f 53 return ret;
36651afe
PC
54 }
55
e7e93965
MM
56 // For testing tr1/type_traits/extent, which has a second template
57 // parameter.
58 template<template<typename, unsigned> class Property,
b0302c68 59 typename Type, unsigned Uint>
e7e93965
MM
60 bool
61 test_property(typename Property<Type, Uint>::value_type value)
62 {
63 bool ret = true;
64 ret &= Property<Type, Uint>::value == value;
65 ret &= Property<Type, Uint>::type::value == value;
66 return ret;
67 }
68
75995f37 69#ifdef __GXX_EXPERIMENTAL_CXX0X__
b0302c68 70 template<template<typename...> class Property, typename... Types>
75995f37 71 bool
b0302c68 72 test_property(typename Property<Types...>::value_type value)
75995f37
PC
73 {
74 bool ret = true;
b0302c68
PC
75 ret &= Property<Types...>::value == value;
76 ret &= Property<Types...>::type::value == value;
75995f37
PC
77 return ret;
78 }
b0302c68
PC
79#endif
80
d63a0e22 81 template<template<typename, typename> class Relationship,
0179f2c6 82 typename Type1, typename Type2>
d63a0e22 83 bool
db5ff236 84 test_relationship(bool value)
d63a0e22
PC
85 {
86 bool ret = true;
db5ff236
PC
87 ret &= Relationship<Type1, Type2>::value == value;
88 ret &= Relationship<Type1, Type2>::type::value == value;
d63a0e22
PC
89 return ret;
90 }
91
0f910b4f
PC
92 // Test types.
93 class ClassType { };
d63a0e22
PC
94 typedef const ClassType cClassType;
95 typedef volatile ClassType vClassType;
96 typedef const volatile ClassType cvClassType;
a9e7ba81 97
c150a271
PC
98 class DerivedType : public ClassType { };
99
dcd400b5 100 enum EnumType { e0 };
a9e7ba81
PC
101
102 struct ConvType
103 { operator int() const; };
f8023b78
PC
104
105 class AbstractClass
59cffcf6 106 {
cff001b2 107 virtual void rotate(int) = 0;
cff001b2 108 };
0179f2c6 109
442dca70 110 class PolymorphicClass
59cffcf6 111 {
cff001b2 112 virtual void rotate(int);
cff001b2 113 };
442dca70 114
59cffcf6 115 class DerivedPolymorphic : public PolymorphicClass { };
442dca70 116
22931aa4
PC
117 class VirtualDestructorClass
118 {
119 virtual ~VirtualDestructorClass();
120 };
121
9e38f702 122 union UnionType { };
0179f2c6 123
516ebd44 124 class IncompleteClass;
0179f2c6 125
75995f37
PC
126 struct ExplicitClass
127 {
128 ExplicitClass(double&);
129 explicit ExplicitClass(int&);
130 };
131
9e38f702
PC
132 int truncate_float(float x) { return (int)x; }
133 long truncate_double(double x) { return (long)x; }
0179f2c6 134
9e38f702
PC
135 struct do_truncate_float_t
136 {
137 do_truncate_float_t()
138 {
139 ++live_objects;
140 }
0179f2c6 141
9e38f702
PC
142 do_truncate_float_t(const do_truncate_float_t&)
143 {
144 ++live_objects;
145 }
59cffcf6 146
9e38f702
PC
147 ~do_truncate_float_t()
148 {
149 --live_objects;
150 }
0179f2c6 151
9e38f702 152 int operator()(float x) { return (int)x; }
59cffcf6 153
9e38f702
PC
154 static int live_objects;
155 };
0179f2c6 156
9e38f702 157 int do_truncate_float_t::live_objects = 0;
0179f2c6 158
9e38f702
PC
159 struct do_truncate_double_t
160 {
161 do_truncate_double_t()
162 {
0179f2c6 163 ++live_objects;
9e38f702 164 }
0179f2c6 165
9e38f702
PC
166 do_truncate_double_t(const do_truncate_double_t&)
167 {
168 ++live_objects;
169 }
0179f2c6 170
9e38f702
PC
171 ~do_truncate_double_t()
172 {
173 --live_objects;
174 }
0179f2c6 175
9e38f702 176 long operator()(double x) { return (long)x; }
59cffcf6 177
9e38f702
PC
178 static int live_objects;
179 };
59cffcf6 180
9e38f702 181 int do_truncate_double_t::live_objects = 0;
59cffcf6 182
9e38f702
PC
183 struct X
184 {
185 int bar;
59cffcf6 186
9e38f702
PC
187 int foo() { return 1; }
188 int foo_c() const { return 2; }
189 int foo_v() volatile { return 3; }
190 int foo_cv() const volatile { return 4; }
191 };
90922b2d
PC
192
193 // For use in 8_c_compatibility.
194 template<typename R, typename T>
dcd400b5 195 typename __gnu_cxx::__enable_if<std::__are_same<R, T>::__value,
105c6331 196 bool>::__type
90922b2d
PC
197 check_ret_type(T)
198 { return true; }
199
59cffcf6 200} // namespace __gnu_test
493bc460
PC
201
202#endif // _GLIBCXX_TESTSUITE_TR1_H