Install gcc-4.3.3-tdm-1-g++.tar.gz
[msysgit.git] / mingw / lib / gcc / mingw32 / 4.3.3 / include / c++ / bits / cpp_type_traits.h
blob103229f6380e8e19f54925b6ae089016b9ce2f35
1 // The -*- C++ -*- type traits classes for internal use in libstdc++
3 // Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
4 // Free Software Foundation, Inc.
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
9 // Free Software Foundation; either version 2, or (at your option)
10 // any later version.
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.
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING. If not, write to the Free
19 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
20 // USA.
22 // As a special exception, you may use this file as part of a free software
23 // library without restriction. Specifically, if other files instantiate
24 // templates or use macros or inline functions from this file, or you compile
25 // this file and link it with other files to produce an executable, this
26 // file does not by itself cause the resulting executable to be covered by
27 // the GNU General Public License. This exception does not however
28 // invalidate any other reasons why the executable file might be covered by
29 // the GNU General Public License.
31 /** @file cpp_type_traits.h
32 * This is an internal header file, included by other library headers.
33 * You should not attempt to use it directly.
36 // Written by Gabriel Dos Reis <dosreis@cmla.ens-cachan.fr>
38 #ifndef _CPP_TYPE_TRAITS_H
39 #define _CPP_TYPE_TRAITS_H 1
41 #pragma GCC system_header
43 #include <bits/c++config.h>
46 // This file provides some compile-time information about various types.
47 // These representations were designed, on purpose, to be constant-expressions
48 // and not types as found in <bits/type_traits.h>. In particular, they
49 // can be used in control structures and the optimizer hopefully will do
50 // the obvious thing.
52 // Why integral expressions, and not functions nor types?
53 // Firstly, these compile-time entities are used as template-arguments
54 // so function return values won't work: We need compile-time entities.
55 // We're left with types and constant integral expressions.
56 // Secondly, from the point of view of ease of use, type-based compile-time
57 // information is -not- *that* convenient. On has to write lots of
58 // overloaded functions and to hope that the compiler will select the right
59 // one. As a net effect, the overall structure isn't very clear at first
60 // glance.
61 // Thirdly, partial ordering and overload resolution (of function templates)
62 // is highly costly in terms of compiler-resource. It is a Good Thing to
63 // keep these resource consumption as least as possible.
65 // See valarray_array.h for a case use.
67 // -- Gaby (dosreis@cmla.ens-cachan.fr) 2000-03-06.
69 // Update 2005: types are also provided and <bits/type_traits.h> has been
70 // removed.
73 // Forward declaration hack, should really include this from somewhere.
74 _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
76 template<typename _Iterator, typename _Container>
77 class __normal_iterator;
79 _GLIBCXX_END_NAMESPACE
81 _GLIBCXX_BEGIN_NAMESPACE(std)
83 struct __true_type { };
84 struct __false_type { };
86 template<bool>
87 struct __truth_type
88 { typedef __false_type __type; };
90 template<>
91 struct __truth_type<true>
92 { typedef __true_type __type; };
94 // N.B. The conversions to bool are needed due to the issue
95 // explained in c++/19404.
96 template<class _Sp, class _Tp>
97 struct __traitor
99 enum { __value = bool(_Sp::__value) || bool(_Tp::__value) };
100 typedef typename __truth_type<__value>::__type __type;
103 // N.B. The conversions to bool are needed due to the issue
104 // explained in c++/19404.
105 template<class _Sp, class _Tp>
106 struct __traitand
108 enum { __value = bool(_Sp::__value) && bool(_Tp::__value) };
109 typedef typename __truth_type<__value>::__type __type;
112 // Compare for equality of types.
113 template<typename, typename>
114 struct __are_same
116 enum { __value = 0 };
117 typedef __false_type __type;
120 template<typename _Tp>
121 struct __are_same<_Tp, _Tp>
123 enum { __value = 1 };
124 typedef __true_type __type;
127 // Holds if the template-argument is a void type.
128 template<typename _Tp>
129 struct __is_void
131 enum { __value = 0 };
132 typedef __false_type __type;
135 template<>
136 struct __is_void<void>
138 enum { __value = 1 };
139 typedef __true_type __type;
143 // Integer types
145 template<typename _Tp>
146 struct __is_integer
148 enum { __value = 0 };
149 typedef __false_type __type;
152 // Thirteen specializations (yes there are eleven standard integer
153 // types; 'long long' and 'unsigned long long' are supported as
154 // extensions)
155 template<>
156 struct __is_integer<bool>
158 enum { __value = 1 };
159 typedef __true_type __type;
162 template<>
163 struct __is_integer<char>
165 enum { __value = 1 };
166 typedef __true_type __type;
169 template<>
170 struct __is_integer<signed char>
172 enum { __value = 1 };
173 typedef __true_type __type;
176 template<>
177 struct __is_integer<unsigned char>
179 enum { __value = 1 };
180 typedef __true_type __type;
183 # ifdef _GLIBCXX_USE_WCHAR_T
184 template<>
185 struct __is_integer<wchar_t>
187 enum { __value = 1 };
188 typedef __true_type __type;
190 # endif
192 template<>
193 struct __is_integer<short>
195 enum { __value = 1 };
196 typedef __true_type __type;
199 template<>
200 struct __is_integer<unsigned short>
202 enum { __value = 1 };
203 typedef __true_type __type;
206 template<>
207 struct __is_integer<int>
209 enum { __value = 1 };
210 typedef __true_type __type;
213 template<>
214 struct __is_integer<unsigned int>
216 enum { __value = 1 };
217 typedef __true_type __type;
220 template<>
221 struct __is_integer<long>
223 enum { __value = 1 };
224 typedef __true_type __type;
227 template<>
228 struct __is_integer<unsigned long>
230 enum { __value = 1 };
231 typedef __true_type __type;
234 template<>
235 struct __is_integer<long long>
237 enum { __value = 1 };
238 typedef __true_type __type;
241 template<>
242 struct __is_integer<unsigned long long>
244 enum { __value = 1 };
245 typedef __true_type __type;
249 // Floating point types
251 template<typename _Tp>
252 struct __is_floating
254 enum { __value = 0 };
255 typedef __false_type __type;
258 // three specializations (float, double and 'long double')
259 template<>
260 struct __is_floating<float>
262 enum { __value = 1 };
263 typedef __true_type __type;
266 template<>
267 struct __is_floating<double>
269 enum { __value = 1 };
270 typedef __true_type __type;
273 template<>
274 struct __is_floating<long double>
276 enum { __value = 1 };
277 typedef __true_type __type;
281 // Pointer types
283 template<typename _Tp>
284 struct __is_pointer
286 enum { __value = 0 };
287 typedef __false_type __type;
290 template<typename _Tp>
291 struct __is_pointer<_Tp*>
293 enum { __value = 1 };
294 typedef __true_type __type;
298 // Normal iterator type
300 template<typename _Tp>
301 struct __is_normal_iterator
303 enum { __value = 0 };
304 typedef __false_type __type;
307 template<typename _Iterator, typename _Container>
308 struct __is_normal_iterator< __gnu_cxx::__normal_iterator<_Iterator,
309 _Container> >
311 enum { __value = 1 };
312 typedef __true_type __type;
316 // An arithmetic type is an integer type or a floating point type
318 template<typename _Tp>
319 struct __is_arithmetic
320 : public __traitor<__is_integer<_Tp>, __is_floating<_Tp> >
321 { };
324 // A fundamental type is `void' or and arithmetic type
326 template<typename _Tp>
327 struct __is_fundamental
328 : public __traitor<__is_void<_Tp>, __is_arithmetic<_Tp> >
329 { };
332 // A scalar type is an arithmetic type or a pointer type
334 template<typename _Tp>
335 struct __is_scalar
336 : public __traitor<__is_arithmetic<_Tp>, __is_pointer<_Tp> >
337 { };
340 // For use in std::copy and std::find overloads for streambuf iterators.
342 template<typename _Tp>
343 struct __is_char
345 enum { __value = 0 };
346 typedef __false_type __type;
349 template<>
350 struct __is_char<char>
352 enum { __value = 1 };
353 typedef __true_type __type;
356 #ifdef _GLIBCXX_USE_WCHAR_T
357 template<>
358 struct __is_char<wchar_t>
360 enum { __value = 1 };
361 typedef __true_type __type;
363 #endif
365 template<typename _Tp>
366 struct __is_byte
368 enum { __value = 0 };
369 typedef __false_type __type;
372 template<>
373 struct __is_byte<char>
375 enum { __value = 1 };
376 typedef __true_type __type;
379 template<>
380 struct __is_byte<signed char>
382 enum { __value = 1 };
383 typedef __true_type __type;
386 template<>
387 struct __is_byte<unsigned char>
389 enum { __value = 1 };
390 typedef __true_type __type;
394 // Move iterator type
396 template<typename _Tp>
397 struct __is_move_iterator
399 enum { __value = 0 };
400 typedef __false_type __type;
403 #ifdef __GXX_EXPERIMENTAL_CXX0X__
404 template<typename _Iterator>
405 class move_iterator;
407 template<typename _Iterator>
408 struct __is_move_iterator< move_iterator<_Iterator> >
410 enum { __value = 1 };
411 typedef __true_type __type;
413 #endif
415 _GLIBCXX_END_NAMESPACE
417 #endif //_CPP_TYPE_TRAITS_H