]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/include/bits/cpp_type_traits.h
1 // The -*- C++ -*- type traits classes for internal use in libstdc++
3 // Copyright (C) 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
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)
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.
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,
21 // As a special exception, you may use this file as part of a free software
22 // library without restriction. Specifically, if other files instantiate
23 // templates or use macros or inline functions from this file, or you compile
24 // this file and link it with other files to produce an executable, this
25 // file does not by itself cause the resulting executable to be covered by
26 // the GNU General Public License. This exception does not however
27 // invalidate any other reasons why the executable file might be covered by
28 // the GNU General Public License.
30 // Written by Gabriel Dos Reis <dosreis@cmla.ens-cachan.fr>
32 /** @file cpp_type_traits.h
33 * This is an internal header file, included by other library headers.
34 * You should not attempt to use it directly.
37 #ifndef _CPP_TYPE_TRAITS_H
38 #define _CPP_TYPE_TRAITS_H 1
40 #pragma GCC system_header
43 // This file provides some compile-time information about various types.
44 // These representations were designed, on purpose, to be constant-expressions
45 // and not types as found in <stl/bits/type_traits.h>. In particular, they
46 // can be used in control structures and the optimizer hopefully will do
49 // Why integral expressions, and not functions nor types?
50 // Firstly, these compile-time entities are used as template-arguments
51 // so function return values won't work: We need compile-time entities.
52 // We're left with types and constant integral expressions.
53 // Secondly, from the point of view of ease of use, type-based compile-time
54 // information is -not- *that* convenient. On has to write lots of
55 // overloaded functions and to hope that the compiler will select the right
56 // one. As a net effect, the overall structure isn't very clear at first
58 // Thirdly, partial ordering and overload resolution (of function templates)
59 // is highly costly in terms of compiler-resource. It is a Good Thing to
60 // keep these resource consumption as least as possible.
62 // See valarray_array.h for a case use.
64 // -- Gaby (dosreis@cmla.ens-cachan.fr) 2000-03-06.
69 // Compare for equality of types.
70 template<typename
, typename
>
79 template<typename _Tp
>
80 struct __are_same
<_Tp
, _Tp
>
88 // Define a nested type if some predicate holds.
89 template<typename
, bool>
94 template<typename _Tp
>
95 struct __enable_if
<_Tp
, true>
100 // Holds if the template-argument is a void type.
101 template<typename _Tp
>
111 struct __is_void
<void>
122 template<typename _Tp
>
131 // Thirteen specializations (yes there are eleven standard integer
132 // types; 'long long' and 'unsigned long long' are supported as
135 struct __is_integer
<bool>
144 struct __is_integer
<char>
153 struct __is_integer
<signed char>
162 struct __is_integer
<unsigned char>
170 # ifdef _GLIBCXX_USE_WCHAR_T
172 struct __is_integer
<wchar_t>
182 struct __is_integer
<short>
191 struct __is_integer
<unsigned short>
200 struct __is_integer
<int>
209 struct __is_integer
<unsigned int>
218 struct __is_integer
<long>
227 struct __is_integer
<unsigned long>
236 struct __is_integer
<long long>
245 struct __is_integer
<unsigned long long>
254 // Floating point types
256 template<typename _Tp
>
265 // three specializations (float, double and 'long double')
267 struct __is_floating
<float>
276 struct __is_floating
<double>
285 struct __is_floating
<long double>
294 // An arithmetic type is an integer type or a floating point type
296 template<typename _Tp
>
297 struct __is_arithmetic
301 _M_type
= __is_integer
<_Tp
>::_M_type
|| __is_floating
<_Tp
>::_M_type
306 // A fundamental type is `void' or and arithmetic type
308 template<typename _Tp
>
309 struct __is_fundamental
313 _M_type
= __is_void
<_Tp
>::_M_type
|| __is_arithmetic
<_Tp
>::_M_type
318 // For the immediate use, the following is a good approximation
320 template<typename _Tp
>
325 _M_type
= __is_fundamental
<_Tp
>::_M_type
332 #endif //_CPP_TYPE_TRAITS_H