25 #pragma GCC system_header 27 #include "bits/type_traits.h" 30 #define CXX_GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__) 35 template<
typename T, T V >
36 struct integral_constant
38 static T
const value = V;
40 typedef integral_constant<T, V> type;
43 typedef integral_constant<bool, true> true_type;
44 typedef integral_constant<bool, false> false_type;
46 template<
typename T >
struct remove_reference;
48 template<
typename T >
struct idendity {
typedef T type; };
50 template<
typename T1,
typename T2 >
struct is_same;
52 template<
typename T >
struct remove_const;
54 template<
typename T >
struct remove_volatile;
56 template<
typename T >
struct remove_cv;
58 template<
typename T >
struct remove_pointer;
60 template<
typename T >
struct remove_extent;
62 template<
typename T >
struct remove_all_extents;
66 template<
typename,
typename >
67 struct is_same : false_type {};
69 template<
typename T >
70 struct is_same<T, T> : true_type {};
72 template<
typename T >
73 struct remove_reference {
typedef T type; };
75 template<
typename T >
76 struct remove_reference<T &> {
typedef T type; };
78 #if __cplusplus >= 201103L 79 template<
typename T >
80 struct remove_reference<T &&> {
typedef T type; };
83 template<
typename T >
struct remove_const {
typedef T type; };
84 template<
typename T >
struct remove_const<T const> {
typedef T type; };
86 template<
typename T >
struct remove_volatile {
typedef T type; };
87 template<
typename T >
struct remove_volatile<T volatile> {
typedef T type; };
89 template<
typename T >
90 struct remove_cv {
typedef typename remove_const<typename remove_volatile<T>::type>::type type; };
92 template<
typename T,
typename >
93 struct __remove_pointer_h {
typedef T type; };
95 template<
typename T,
typename I >
96 struct __remove_pointer_h<T, I*> {
typedef I type; };
98 template<
typename T >
99 struct remove_pointer : __remove_pointer_h<T, typename remove_cv<T>::type> {};
102 template<
typename T >
103 struct remove_extent {
typedef T type; };
105 template<
typename T >
106 struct remove_extent<T[]> {
typedef T type; };
108 template<
typename T,
unsigned long N >
109 struct remove_extent<T[N]> {
typedef T type; };
112 template<
typename T >
113 struct remove_all_extents {
typedef T type; };
115 template<
typename T >
116 struct remove_all_extents<T[]> {
typedef typename remove_all_extents<T>::type type; };
118 template<
typename T,
unsigned long N >
119 struct remove_all_extents<T[N]> {
typedef typename remove_all_extents<T>::type type; };
121 #if __cplusplus >= 201103L 123 template<
typename T >
125 forward(
typename cxx::remove_reference<T>::type &t)
126 {
return static_cast<T &&
>(t); }
128 template<
typename T >
130 forward(
typename cxx::remove_reference<T>::type &&t)
131 {
return static_cast<T &&
>(t); }
133 template<
typename T >
134 inline typename cxx::remove_reference<T>::type &&
135 move(T &t) {
return static_cast<typename cxx::remove_reference<T>::type &&
>(t); }
137 template<
typename T >
138 inline T move(T t) {
return t; }
141 template<
bool,
typename T =
void >
144 template<
typename T >
145 struct enable_if<true, T> {
typedef T type; };
147 template<
typename T >
148 struct is_const : false_type {};
150 template<
typename T >
151 struct is_const<T const> : true_type {};
153 template<
bool,
typename,
typename >
156 template<
bool C,
typename T_TRUE,
typename T_FALSE >
157 struct conditional {
typedef T_TRUE type; };
159 template<
typename T_TRUE,
typename T_FALSE >
160 struct conditional< false, T_TRUE, T_FALSE > {
typedef T_FALSE type; };
163 struct is_enum : integral_constant<bool, __is_enum(T)> {};
166 template<
typename T >
struct is_integral : false_type {};
168 template<>
struct is_integral<bool> : true_type {};
170 template<>
struct is_integral<char> : true_type {};
171 template<>
struct is_integral<signed char> : true_type {};
172 template<>
struct is_integral<unsigned char> : true_type {};
173 template<>
struct is_integral<short> : true_type {};
174 template<>
struct is_integral<unsigned short> : true_type {};
175 template<>
struct is_integral<int> : true_type {};
176 template<>
struct is_integral<unsigned int> : true_type {};
177 template<>
struct is_integral<long> : true_type {};
178 template<>
struct is_integral<unsigned long> : true_type {};
179 template<>
struct is_integral<long long> : true_type {};
180 template<>
struct is_integral<unsigned long long> : true_type {};
182 template< typename T, bool = is_integral<T>::value || is_enum<T>::value >
183 struct __is_signed_helper : integral_constant<bool, static_cast<bool>(T(-1) < T(0))> {};
185 template< typename T >
186 struct __is_signed_helper<T, false> : integral_constant<bool, false> {};
188 template< typename T >
189 struct is_signed : __is_signed_helper<T> {};
193 struct is_array : false_type {};
195 template< typename T >
196 struct is_array<T[]> : true_type {};
198 template< typename T, unsigned long N >
199 struct is_array<T[N]> : true_type {};
202 template< int SIZE, bool SIGN = false, bool = true > struct int_type_for_size;
204 template<> struct int_type_for_size<sizeof(char), true, true>
205 { typedef signed char type; };
207 template<> struct int_type_for_size<sizeof(char), false, true>
208 { typedef unsigned char type; };
210 template<> struct int_type_for_size<sizeof(short), true, (sizeof(short) > sizeof(char))>
211 {
typedef short type; };
213 template<>
struct int_type_for_size<sizeof(short), false, (sizeof(short) > sizeof(char))>
214 {
typedef unsigned short type; };
216 template<>
struct int_type_for_size<sizeof(int), true, (sizeof(int) > sizeof(short))>
217 {
typedef int type; };
219 template<>
struct int_type_for_size<sizeof(int), false, (sizeof(int) > sizeof(short))>
220 {
typedef unsigned int type; };
222 template<>
struct int_type_for_size<sizeof(long), true, (sizeof(long) > sizeof(int))>
223 {
typedef long type; };
225 template<>
struct int_type_for_size<sizeof(long), false, (sizeof(long) > sizeof(int))>
226 {
typedef unsigned long type; };
228 template<>
struct int_type_for_size<sizeof(long long), true, (sizeof(long long) > sizeof(long))>
229 {
typedef long long type; };
231 template<>
struct int_type_for_size<sizeof(long long), false, (sizeof(long long) > sizeof(long))>
232 {
typedef unsigned long long type; };
234 template<
typename T,
class Enable =
void >
struct underlying_type {};
236 template<
typename T >
237 struct underlying_type<T, typename enable_if<is_enum<T>::value>::type >
239 typedef typename int_type_for_size<sizeof(T), is_signed<T>::value>::type type;
242 template<
typename T >
struct make_signed;
243 template<>
struct make_signed<char> {
typedef signed char type; };
244 template<>
struct make_signed<unsigned char> {
typedef signed char type; };
245 template<>
struct make_signed<signed char> {
typedef signed char type; };
246 template<>
struct make_signed<unsigned int> {
typedef signed int type; };
247 template<>
struct make_signed<signed int> {
typedef signed int type; };
248 template<>
struct make_signed<unsigned long int> {
typedef signed long int type; };
249 template<>
struct make_signed<signed long int> {
typedef signed long int type; };
250 template<>
struct make_signed<unsigned long long int> {
typedef signed long long int type; };
251 template<>
struct make_signed<signed long long int> {
typedef signed long long int type; };
253 template<
typename T >
struct make_unsigned;
254 template<>
struct make_unsigned<char> {
typedef unsigned char type; };
255 template<>
struct make_unsigned<unsigned char> {
typedef unsigned char type; };
256 template<>
struct make_unsigned<signed char> {
typedef unsigned char type; };
257 template<>
struct make_unsigned<unsigned int> {
typedef unsigned int type; };
258 template<>
struct make_unsigned<signed int> {
typedef unsigned int type; };
259 template<>
struct make_unsigned<unsigned long int> {
typedef unsigned long int type; };
260 template<>
struct make_unsigned<signed long int> {
typedef unsigned long int type; };
261 template<>
struct make_unsigned<unsigned long long int> {
typedef unsigned long long int type; };
262 template<>
struct make_unsigned<signed long long int> {
typedef unsigned long long int type; };
265 template<
typename From,
typename To>
266 struct is_convertible
269 struct _true {
char x[2]; };
272 static _true _helper(To
const *);
273 static _false _helper(...);
277 value =
sizeof(_true) ==
sizeof(_helper(static_cast<From*>(0)))
281 typedef bool value_type;