3 // Copyright (C) 2005-2014 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 terms
7 // of the GNU General Public License as published by the Free Software
8 // Foundation; either version 3, or (at your option) any later
11 // This library is distributed in the hope that it will be useful, but
12 // WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // General Public License for more details.
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
25 /** @file ext/type_traits.h
26 * This file is a GNU extension to the Standard C++ Library.
29 #ifndef _EXT_TYPE_TRAITS
30 #define _EXT_TYPE_TRAITS 1
32 #pragma GCC system_header
34 #include <bits/c++config.h>
35 #include <bits/cpp_type_traits.h>
37 namespace __gnu_cxx
_GLIBCXX_VISIBILITY(default)
39 _GLIBCXX_BEGIN_NAMESPACE_VERSION
41 // Define a nested type if some predicate holds.
42 template<bool, typename
>
46 template<typename _Tp
>
47 struct __enable_if
<true, _Tp
>
48 { typedef _Tp __type
; };
51 // Conditional expression for types. If true, first, if false, second.
52 template<bool _Cond
, typename _Iftrue
, typename _Iffalse
>
53 struct __conditional_type
54 { typedef _Iftrue __type
; };
56 template<typename _Iftrue
, typename _Iffalse
>
57 struct __conditional_type
<false, _Iftrue
, _Iffalse
>
58 { typedef _Iffalse __type
; };
61 // Given an integral builtin type, return the corresponding unsigned type.
62 template<typename _Tp
>
66 typedef __enable_if
<std::__is_integer
<_Tp
>::__value
, _Tp
> __if_type
;
69 typedef typename
__if_type::__type __type
;
73 struct __add_unsigned
<char>
74 { typedef unsigned char __type
; };
77 struct __add_unsigned
<signed char>
78 { typedef unsigned char __type
; };
81 struct __add_unsigned
<short>
82 { typedef unsigned short __type
; };
85 struct __add_unsigned
<int>
86 { typedef unsigned int __type
; };
89 struct __add_unsigned
<long>
90 { typedef unsigned long __type
; };
93 struct __add_unsigned
<long long>
94 { typedef unsigned long long __type
; };
96 // Declare but don't define.
98 struct __add_unsigned
<bool>;
101 struct __add_unsigned
<wchar_t>;
104 // Given an integral builtin type, return the corresponding signed type.
105 template<typename _Tp
>
106 struct __remove_unsigned
109 typedef __enable_if
<std::__is_integer
<_Tp
>::__value
, _Tp
> __if_type
;
112 typedef typename
__if_type::__type __type
;
116 struct __remove_unsigned
<char>
117 { typedef signed char __type
; };
120 struct __remove_unsigned
<unsigned char>
121 { typedef signed char __type
; };
124 struct __remove_unsigned
<unsigned short>
125 { typedef short __type
; };
128 struct __remove_unsigned
<unsigned int>
129 { typedef int __type
; };
132 struct __remove_unsigned
<unsigned long>
133 { typedef long __type
; };
136 struct __remove_unsigned
<unsigned long long>
137 { typedef long long __type
; };
139 // Declare but don't define.
141 struct __remove_unsigned
<bool>;
144 struct __remove_unsigned
<wchar_t>;
147 // For use in string and vstring.
148 template<typename _Type
>
150 __is_null_pointer(_Type
* __ptr
)
151 { return __ptr
== 0; }
153 template<typename _Type
>
155 __is_null_pointer(_Type
)
158 #if __cplusplus >= 201103L
160 __is_null_pointer(std::nullptr_t
)
164 // For complex and cmath
165 template<typename _Tp
, bool = std::__is_integer
<_Tp
>::__value
>
167 { typedef double __type
; };
169 // No nested __type member for non-integer non-floating point types,
170 // allows this type to be used for SFINAE to constrain overloads in
171 // <cmath> and <complex> to only the intended types.
172 template<typename _Tp
>
173 struct __promote
<_Tp
, false>
177 struct __promote
<long double>
178 { typedef long double __type
; };
181 struct __promote
<double>
182 { typedef double __type
; };
185 struct __promote
<float>
186 { typedef float __type
; };
188 template<typename _Tp
, typename _Up
,
189 typename _Tp2
= typename __promote
<_Tp
>::__type
,
190 typename _Up2
= typename __promote
<_Up
>::__type
>
193 typedef __typeof__(_Tp2() + _Up2()) __type
;
196 template<typename _Tp
, typename _Up
, typename _Vp
,
197 typename _Tp2
= typename __promote
<_Tp
>::__type
,
198 typename _Up2
= typename __promote
<_Up
>::__type
,
199 typename _Vp2
= typename __promote
<_Vp
>::__type
>
202 typedef __typeof__(_Tp2() + _Up2() + _Vp2()) __type
;
205 template<typename _Tp
, typename _Up
, typename _Vp
, typename _Wp
,
206 typename _Tp2
= typename __promote
<_Tp
>::__type
,
207 typename _Up2
= typename __promote
<_Up
>::__type
,
208 typename _Vp2
= typename __promote
<_Vp
>::__type
,
209 typename _Wp2
= typename __promote
<_Wp
>::__type
>
212 typedef __typeof__(_Tp2() + _Up2() + _Vp2() + _Wp2()) __type
;
215 _GLIBCXX_END_NAMESPACE_VERSION