type_traits: Implement is_const and is_volatile.
[gcc.git] / libstdc++-v3 / include / tr1 / type_traits
1 // TR1 type_traits -*- C++ -*-
2
3 // Copyright (C) 2004 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 2, or (at your option)
9 // any later version.
10
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING. If not, write to the Free
18 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19 // USA.
20
21 /** @file
22 * This is a TR1 C++ Library header.
23 */
24
25 #ifndef _TYPE_TRAITS
26 #define _TYPE_TRAITS 1
27
28 #include <bits/c++config.h>
29 #include <cstddef>
30
31 //namespace std::tr1
32 namespace std
33 {
34 namespace tr1
35 {
36 /// @brief helper classes [4.3].
37 template<typename _Tp, _Tp __v>
38 struct integral_constant
39 {
40 static const _Tp value = __v;
41 typedef _Tp value_type;
42 typedef integral_constant<_Tp, __v> type;
43 };
44 typedef integral_constant<bool, true> true_type;
45 typedef integral_constant<bool, false> false_type;
46
47 #define _DEFINE_PRIMARY_SPEC_HELPER(_Primary, _Type) \
48 template<> \
49 struct _Primary<_Type> \
50 : public true_type { };
51
52 #define _DEFINE_PRIMARY_SPEC(_Primary, _Type) \
53 _DEFINE_PRIMARY_SPEC_HELPER(_Primary, _Type) \
54 _DEFINE_PRIMARY_SPEC_HELPER(_Primary, _Type const) \
55 _DEFINE_PRIMARY_SPEC_HELPER(_Primary, _Type volatile) \
56 _DEFINE_PRIMARY_SPEC_HELPER(_Primary, _Type const volatile)
57
58 /// @brief primary type categories [4.5.1].
59 template<typename>
60 struct is_void
61 : public false_type { };
62 _DEFINE_PRIMARY_SPEC(is_void, void)
63
64 template<typename>
65 struct is_integral
66 : public false_type { };
67 _DEFINE_PRIMARY_SPEC(is_integral, bool)
68 _DEFINE_PRIMARY_SPEC(is_integral, char)
69 _DEFINE_PRIMARY_SPEC(is_integral, signed char)
70 _DEFINE_PRIMARY_SPEC(is_integral, unsigned char)
71 #ifdef _GLIBCXX_USE_WCHAR_T
72 _DEFINE_PRIMARY_SPEC(is_integral, wchar_t)
73 #endif
74 _DEFINE_PRIMARY_SPEC(is_integral, short)
75 _DEFINE_PRIMARY_SPEC(is_integral, unsigned short)
76 _DEFINE_PRIMARY_SPEC(is_integral, int)
77 _DEFINE_PRIMARY_SPEC(is_integral, unsigned int)
78 _DEFINE_PRIMARY_SPEC(is_integral, long)
79 _DEFINE_PRIMARY_SPEC(is_integral, unsigned long)
80 _DEFINE_PRIMARY_SPEC(is_integral, long long)
81 _DEFINE_PRIMARY_SPEC(is_integral, unsigned long long)
82
83 template<typename>
84 struct is_floating_point
85 : public false_type { };
86 _DEFINE_PRIMARY_SPEC(is_floating_point, float)
87 _DEFINE_PRIMARY_SPEC(is_floating_point, double)
88 _DEFINE_PRIMARY_SPEC(is_floating_point, long double)
89
90 template<typename>
91 struct is_array
92 : public false_type { };
93
94 template<typename _Tp, std::size_t _Size>
95 struct is_array<_Tp[_Size]>
96 : public true_type { };
97
98 template<typename _Tp>
99 struct is_array<_Tp[]>
100 : public true_type { };
101
102 template<typename _Tp>
103 struct is_pointer;
104
105 template<typename>
106 struct is_reference
107 : public false_type { };
108
109 template<typename _Tp>
110 struct is_reference<_Tp&>
111 : public true_type { };
112
113 template<typename _Tp>
114 struct is_member_object_pointer;
115
116 template<typename _Tp>
117 struct is_member_function_pointer;
118
119 template<typename _Tp>
120 struct is_enum;
121
122 template<typename _Tp>
123 struct is_union;
124
125 template<typename _Tp>
126 struct is_class;
127
128 template<typename _Tp>
129 struct is_function;
130
131 #undef _DEFINE_PRIMARY_SPEC_HELPER
132 #undef _DEFINE_PRIMARY_SPEC
133
134 /// @brief composite type traits [4.5.2].
135 template<typename _Tp>
136 struct is_arithmetic
137 : public integral_constant<bool, (is_integral<_Tp>::value
138 || is_floating_point<_Tp>::value)>
139 { };
140
141 template<typename _Tp>
142 struct is_fundamental
143 : public integral_constant<bool, (is_arithmetic<_Tp>::value
144 || is_void<_Tp>::value)>
145 { };
146
147 template<typename _Tp>
148 struct is_object
149 : public integral_constant<bool, !(is_function<_Tp>::value
150 || is_reference<_Tp>::value
151 || is_void<_Tp>::value)>
152 { };
153
154 template<typename _Tp>
155 struct is_member_pointer
156 : public integral_constant<bool,
157 (is_member_object_pointer<_Tp>::value
158 || is_member_function_pointer<_Tp>::value)>
159 { };
160
161 template<typename _Tp>
162 struct is_scalar
163 : public integral_constant<bool, (is_arithmetic<_Tp>::value
164 || is_enum<_Tp>::value
165 || is_pointer<_Tp>::value
166 || is_member_pointer<_Tp>::value)>
167 { };
168
169 template<typename _Tp>
170 struct is_compound
171 : public integral_constant<bool, !is_fundamental<_Tp>::value> { };
172
173 /// @brief type properties [4.5.3].
174 template<typename>
175 struct is_const
176 : public false_type { };
177
178 template<typename _Tp>
179 struct is_const<_Tp const>
180 : public true_type { };
181
182 template<typename>
183 struct is_volatile
184 : public false_type { };
185
186 template<typename _Tp>
187 struct is_volatile<_Tp volatile>
188 : public true_type { };
189
190 template<typename _Tp>
191 struct is_pod;
192
193 template<typename _Tp>
194 struct is_empty;
195
196 template<typename _Tp>
197 struct is_polymorphic;
198
199 template<typename _Tp>
200 struct is_abstract;
201
202 template<typename _Tp>
203 struct has_trivial_constructor;
204
205 template<typename _Tp>
206 struct has_trivial_copy;
207
208 template<typename _Tp>
209 struct has_trivial_assign;
210
211 template<typename _Tp>
212 struct has_trivial_destructor;
213
214 template<typename _Tp>
215 struct has_nothrow_constructor;
216
217 template<typename _Tp>
218 struct has_nothrow_copy;
219
220 template<typename _Tp>
221 struct has_nothrow_assign;
222
223 template<typename _Tp>
224 struct has_virtual_destructor
225 : public false_type { };
226
227 template<typename _Tp>
228 struct is_signed;
229
230 template<typename _Tp>
231 struct is_unsigned;
232
233 template<typename _Tp>
234 struct alignment_of;
235
236 template<typename _Tp>
237 struct rank;
238
239 template<typename _Tp, unsigned _Uint = 0>
240 struct extent;
241
242 /// @brief relationships between types [4.6].
243 template<typename _Tp, typename _Up>
244 struct is_same;
245
246 template<typename _From, typename _To>
247 struct is_convertible;
248
249 template<typename _Base, typename _Derived>
250 struct is_base_of;
251
252 /// @brief const-volatile modifications [4.7.1].
253 template<typename _Tp>
254 struct remove_const;
255
256 template<typename _Tp>
257 struct remove_volatile;
258
259 template<typename _Tp>
260 struct remove_cv;
261
262 template<typename _Tp>
263 struct add_const;
264
265 template<typename _Tp>
266 struct add_volatile;
267
268 template<typename _Tp>
269 struct add_cv;
270
271 /// @brief reference modifications [4.7.2].
272 template<typename _Tp>
273 struct remove_reference;
274
275 template<typename _Tp>
276 struct add_reference;
277
278 /// @brief array modififications [4.7.3].
279 template<typename _Tp>
280 struct remove_extent;
281
282 template<typename _Tp>
283 struct remove_all_extents;
284
285 /// @brief pointer modifications [4.7.4].
286 template<typename _Tp>
287 struct remove_pointer;
288
289 template<typename _Tp>
290 struct add_pointer;
291
292 /// @brief other transformations [4.8].
293 template<std::size_t _Len, std::size_t _Align>
294 struct aligned_storage;
295 }
296 }
297
298 #endif