]>
Commit | Line | Data |
---|---|---|
c0ffa2ba | 1 | // C++11 <type_traits> -*- C++ -*- |
af13a7a6 | 2 | |
aa118a03 | 3 | // Copyright (C) 2007-2014 Free Software Foundation, Inc. |
af13a7a6 BK |
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 | |
748086b7 | 8 | // Free Software Foundation; either version 3, or (at your option) |
af13a7a6 BK |
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 | ||
748086b7 JJ |
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. | |
19 | ||
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/>. | |
af13a7a6 BK |
24 | |
25 | /** @file include/type_traits | |
26 | * This is a Standard C++ Library header. | |
27 | */ | |
28 | ||
4514bed6 BK |
29 | #ifndef _GLIBCXX_TYPE_TRAITS |
30 | #define _GLIBCXX_TYPE_TRAITS 1 | |
af13a7a6 BK |
31 | |
32 | #pragma GCC system_header | |
33 | ||
734f5023 | 34 | #if __cplusplus < 201103L |
ab65a4c7 | 35 | # include <bits/c++0x_warning.h> |
57317d2a | 36 | #else |
af13a7a6 | 37 | |
8fc81078 | 38 | #include <bits/c++config.h> |
e133ace8 | 39 | |
c0eef1c8 JW |
40 | #ifdef _GLIBCXX_USE_C99_STDINT_TR1 |
41 | # if defined (__UINT_LEAST16_TYPE__) && defined(__UINT_LEAST32_TYPE__) | |
21e2806a JW |
42 | namespace std |
43 | { | |
c0eef1c8 JW |
44 | typedef __UINT_LEAST16_TYPE__ uint_least16_t; |
45 | typedef __UINT_LEAST32_TYPE__ uint_least32_t; | |
21e2806a | 46 | } |
c0eef1c8 JW |
47 | # else |
48 | # include <cstdint> | |
49 | # endif | |
50 | #endif | |
51 | ||
21e2806a JW |
52 | namespace std _GLIBCXX_VISIBILITY(default) |
53 | { | |
54 | _GLIBCXX_BEGIN_NAMESPACE_VERSION | |
55 | ||
8e32aa11 | 56 | /** |
c0ffa2ba | 57 | * @defgroup metaprogramming Metaprogramming |
13901e4b JW |
58 | * @ingroup utilities |
59 | * | |
60 | * Template utilities for compile-time introspection and modification, | |
61 | * including type classification traits, type property inspection traits | |
62 | * and type transformation traits. | |
63 | * | |
5b9daa7e BK |
64 | * @{ |
65 | */ | |
ac65b7d2 DK |
66 | |
67 | /// integral_constant | |
68 | template<typename _Tp, _Tp __v> | |
69 | struct integral_constant | |
70 | { | |
71 | static constexpr _Tp value = __v; | |
72 | typedef _Tp value_type; | |
73 | typedef integral_constant<_Tp, __v> type; | |
9191d7a8 | 74 | constexpr operator value_type() const { return value; } |
db113eda | 75 | #if __cplusplus > 201103L |
a15f7cb8 ESR |
76 | |
77 | #define __cpp_lib_integral_constant_callable 201304 | |
78 | ||
db113eda JW |
79 | constexpr value_type operator()() const { return value; } |
80 | #endif | |
ac65b7d2 DK |
81 | }; |
82 | ||
c0ffa2ba BK |
83 | template<typename _Tp, _Tp __v> |
84 | constexpr _Tp integral_constant<_Tp, __v>::value; | |
85 | ||
13901e4b | 86 | /// The type used as a compile-time boolean with true value. |
ac65b7d2 DK |
87 | typedef integral_constant<bool, true> true_type; |
88 | ||
13901e4b | 89 | /// The type used as a compile-time boolean with false value. |
ac65b7d2 DK |
90 | typedef integral_constant<bool, false> false_type; |
91 | ||
123c516a | 92 | // Meta programming helper types. |
53dc5044 | 93 | |
123c516a PC |
94 | template<bool, typename, typename> |
95 | struct conditional; | |
53dc5044 | 96 | |
dd7b175e | 97 | template<typename...> |
123c516a PC |
98 | struct __or_; |
99 | ||
ac65b7d2 DK |
100 | template<> |
101 | struct __or_<> | |
102 | : public false_type | |
103 | { }; | |
104 | ||
dd7b175e PC |
105 | template<typename _B1> |
106 | struct __or_<_B1> | |
107 | : public _B1 | |
108 | { }; | |
109 | ||
123c516a PC |
110 | template<typename _B1, typename _B2> |
111 | struct __or_<_B1, _B2> | |
112 | : public conditional<_B1::value, _B1, _B2>::type | |
113 | { }; | |
114 | ||
115 | template<typename _B1, typename _B2, typename _B3, typename... _Bn> | |
116 | struct __or_<_B1, _B2, _B3, _Bn...> | |
117 | : public conditional<_B1::value, _B1, __or_<_B2, _B3, _Bn...>>::type | |
118 | { }; | |
53dc5044 | 119 | |
dd7b175e | 120 | template<typename...> |
123c516a | 121 | struct __and_; |
53dc5044 | 122 | |
ac65b7d2 DK |
123 | template<> |
124 | struct __and_<> | |
125 | : public true_type | |
126 | { }; | |
127 | ||
dd7b175e PC |
128 | template<typename _B1> |
129 | struct __and_<_B1> | |
130 | : public _B1 | |
131 | { }; | |
132 | ||
123c516a PC |
133 | template<typename _B1, typename _B2> |
134 | struct __and_<_B1, _B2> | |
135 | : public conditional<_B1::value, _B2, _B1>::type | |
136 | { }; | |
137 | ||
138 | template<typename _B1, typename _B2, typename _B3, typename... _Bn> | |
139 | struct __and_<_B1, _B2, _B3, _Bn...> | |
140 | : public conditional<_B1::value, __and_<_B2, _B3, _Bn...>, _B1>::type | |
141 | { }; | |
142 | ||
143 | template<typename _Pp> | |
144 | struct __not_ | |
145 | : public integral_constant<bool, !_Pp::value> | |
146 | { }; | |
147 | ||
b3618b71 DK |
148 | // For several sfinae-friendly trait implementations we transport both the |
149 | // result information (as the member type) and the failure information (no | |
150 | // member type). This is very similar to std::enable_if, but we cannot use | |
151 | // them, because we need to derive from them as an implementation detail. | |
152 | ||
153 | template<typename _Tp> | |
154 | struct __success_type | |
155 | { typedef _Tp type; }; | |
156 | ||
157 | struct __failure_type | |
158 | { }; | |
159 | ||
c0ffa2ba | 160 | // Primary type categories. |
123c516a | 161 | |
53dc5044 PC |
162 | template<typename> |
163 | struct remove_cv; | |
164 | ||
165 | template<typename> | |
166 | struct __is_void_helper | |
167 | : public false_type { }; | |
53dc5044 | 168 | |
123c516a PC |
169 | template<> |
170 | struct __is_void_helper<void> | |
171 | : public true_type { }; | |
53dc5044 PC |
172 | |
173 | /// is_void | |
174 | template<typename _Tp> | |
175 | struct is_void | |
82b12c4b | 176 | : public __is_void_helper<typename remove_cv<_Tp>::type>::type |
53dc5044 PC |
177 | { }; |
178 | ||
179 | template<typename> | |
180 | struct __is_integral_helper | |
181 | : public false_type { }; | |
123c516a PC |
182 | |
183 | template<> | |
184 | struct __is_integral_helper<bool> | |
185 | : public true_type { }; | |
186 | ||
187 | template<> | |
188 | struct __is_integral_helper<char> | |
189 | : public true_type { }; | |
190 | ||
191 | template<> | |
192 | struct __is_integral_helper<signed char> | |
193 | : public true_type { }; | |
194 | ||
195 | template<> | |
196 | struct __is_integral_helper<unsigned char> | |
197 | : public true_type { }; | |
198 | ||
53dc5044 | 199 | #ifdef _GLIBCXX_USE_WCHAR_T |
123c516a PC |
200 | template<> |
201 | struct __is_integral_helper<wchar_t> | |
202 | : public true_type { }; | |
53dc5044 | 203 | #endif |
123c516a PC |
204 | |
205 | template<> | |
206 | struct __is_integral_helper<char16_t> | |
207 | : public true_type { }; | |
208 | ||
209 | template<> | |
210 | struct __is_integral_helper<char32_t> | |
211 | : public true_type { }; | |
212 | ||
213 | template<> | |
214 | struct __is_integral_helper<short> | |
215 | : public true_type { }; | |
216 | ||
217 | template<> | |
218 | struct __is_integral_helper<unsigned short> | |
219 | : public true_type { }; | |
220 | ||
221 | template<> | |
222 | struct __is_integral_helper<int> | |
223 | : public true_type { }; | |
224 | ||
225 | template<> | |
226 | struct __is_integral_helper<unsigned int> | |
227 | : public true_type { }; | |
228 | ||
229 | template<> | |
230 | struct __is_integral_helper<long> | |
231 | : public true_type { }; | |
232 | ||
233 | template<> | |
234 | struct __is_integral_helper<unsigned long> | |
235 | : public true_type { }; | |
236 | ||
237 | template<> | |
238 | struct __is_integral_helper<long long> | |
239 | : public true_type { }; | |
240 | ||
241 | template<> | |
242 | struct __is_integral_helper<unsigned long long> | |
243 | : public true_type { }; | |
53dc5044 | 244 | |
6d585f01 PC |
245 | #if !defined(__STRICT_ANSI__) && defined(_GLIBCXX_USE_INT128) |
246 | template<> | |
fd1e62c2 | 247 | struct __is_integral_helper<__int128> |
6d585f01 PC |
248 | : public true_type { }; |
249 | ||
250 | template<> | |
fd1e62c2 | 251 | struct __is_integral_helper<unsigned __int128> |
6d585f01 PC |
252 | : public true_type { }; |
253 | #endif | |
254 | ||
53dc5044 PC |
255 | /// is_integral |
256 | template<typename _Tp> | |
257 | struct is_integral | |
82b12c4b | 258 | : public __is_integral_helper<typename remove_cv<_Tp>::type>::type |
53dc5044 PC |
259 | { }; |
260 | ||
261 | template<typename> | |
262 | struct __is_floating_point_helper | |
263 | : public false_type { }; | |
123c516a PC |
264 | |
265 | template<> | |
266 | struct __is_floating_point_helper<float> | |
267 | : public true_type { }; | |
268 | ||
269 | template<> | |
270 | struct __is_floating_point_helper<double> | |
271 | : public true_type { }; | |
272 | ||
273 | template<> | |
274 | struct __is_floating_point_helper<long double> | |
275 | : public true_type { }; | |
53dc5044 | 276 | |
6d585f01 PC |
277 | #if !defined(__STRICT_ANSI__) && defined(_GLIBCXX_USE_FLOAT128) |
278 | template<> | |
279 | struct __is_floating_point_helper<__float128> | |
280 | : public true_type { }; | |
281 | #endif | |
282 | ||
53dc5044 PC |
283 | /// is_floating_point |
284 | template<typename _Tp> | |
285 | struct is_floating_point | |
82b12c4b | 286 | : public __is_floating_point_helper<typename remove_cv<_Tp>::type>::type |
53dc5044 PC |
287 | { }; |
288 | ||
289 | /// is_array | |
290 | template<typename> | |
291 | struct is_array | |
292 | : public false_type { }; | |
293 | ||
294 | template<typename _Tp, std::size_t _Size> | |
295 | struct is_array<_Tp[_Size]> | |
296 | : public true_type { }; | |
297 | ||
298 | template<typename _Tp> | |
299 | struct is_array<_Tp[]> | |
300 | : public true_type { }; | |
301 | ||
302 | template<typename> | |
303 | struct __is_pointer_helper | |
304 | : public false_type { }; | |
123c516a PC |
305 | |
306 | template<typename _Tp> | |
307 | struct __is_pointer_helper<_Tp*> | |
308 | : public true_type { }; | |
53dc5044 PC |
309 | |
310 | /// is_pointer | |
311 | template<typename _Tp> | |
312 | struct is_pointer | |
82b12c4b | 313 | : public __is_pointer_helper<typename remove_cv<_Tp>::type>::type |
53dc5044 PC |
314 | { }; |
315 | ||
123c516a PC |
316 | /// is_lvalue_reference |
317 | template<typename> | |
318 | struct is_lvalue_reference | |
319 | : public false_type { }; | |
320 | ||
53dc5044 | 321 | template<typename _Tp> |
123c516a PC |
322 | struct is_lvalue_reference<_Tp&> |
323 | : public true_type { }; | |
324 | ||
325 | /// is_rvalue_reference | |
326 | template<typename> | |
327 | struct is_rvalue_reference | |
328 | : public false_type { }; | |
53dc5044 | 329 | |
53dc5044 | 330 | template<typename _Tp> |
123c516a PC |
331 | struct is_rvalue_reference<_Tp&&> |
332 | : public true_type { }; | |
333 | ||
334 | template<typename> | |
53dc5044 PC |
335 | struct is_function; |
336 | ||
337 | template<typename> | |
338 | struct __is_member_object_pointer_helper | |
339 | : public false_type { }; | |
123c516a PC |
340 | |
341 | template<typename _Tp, typename _Cp> | |
342 | struct __is_member_object_pointer_helper<_Tp _Cp::*> | |
343 | : public integral_constant<bool, !is_function<_Tp>::value> { }; | |
53dc5044 PC |
344 | |
345 | /// is_member_object_pointer | |
346 | template<typename _Tp> | |
347 | struct is_member_object_pointer | |
82b12c4b FD |
348 | : public __is_member_object_pointer_helper< |
349 | typename remove_cv<_Tp>::type>::type | |
53dc5044 PC |
350 | { }; |
351 | ||
352 | template<typename> | |
353 | struct __is_member_function_pointer_helper | |
354 | : public false_type { }; | |
123c516a PC |
355 | |
356 | template<typename _Tp, typename _Cp> | |
357 | struct __is_member_function_pointer_helper<_Tp _Cp::*> | |
358 | : public integral_constant<bool, is_function<_Tp>::value> { }; | |
53dc5044 PC |
359 | |
360 | /// is_member_function_pointer | |
361 | template<typename _Tp> | |
362 | struct is_member_function_pointer | |
82b12c4b FD |
363 | : public __is_member_function_pointer_helper< |
364 | typename remove_cv<_Tp>::type>::type | |
53dc5044 PC |
365 | { }; |
366 | ||
367 | /// is_enum | |
368 | template<typename _Tp> | |
369 | struct is_enum | |
370 | : public integral_constant<bool, __is_enum(_Tp)> | |
371 | { }; | |
372 | ||
373 | /// is_union | |
374 | template<typename _Tp> | |
375 | struct is_union | |
376 | : public integral_constant<bool, __is_union(_Tp)> | |
377 | { }; | |
378 | ||
379 | /// is_class | |
380 | template<typename _Tp> | |
381 | struct is_class | |
382 | : public integral_constant<bool, __is_class(_Tp)> | |
383 | { }; | |
384 | ||
385 | /// is_function | |
386 | template<typename> | |
387 | struct is_function | |
388 | : public false_type { }; | |
123c516a | 389 | |
53dc5044 PC |
390 | template<typename _Res, typename... _ArgTypes> |
391 | struct is_function<_Res(_ArgTypes...)> | |
392 | : public true_type { }; | |
123c516a | 393 | |
89898034 DK |
394 | template<typename _Res, typename... _ArgTypes> |
395 | struct is_function<_Res(_ArgTypes...) &> | |
396 | : public true_type { }; | |
397 | ||
398 | template<typename _Res, typename... _ArgTypes> | |
399 | struct is_function<_Res(_ArgTypes...) &&> | |
400 | : public true_type { }; | |
401 | ||
53dc5044 PC |
402 | template<typename _Res, typename... _ArgTypes> |
403 | struct is_function<_Res(_ArgTypes......)> | |
404 | : public true_type { }; | |
123c516a | 405 | |
89898034 DK |
406 | template<typename _Res, typename... _ArgTypes> |
407 | struct is_function<_Res(_ArgTypes......) &> | |
408 | : public true_type { }; | |
409 | ||
410 | template<typename _Res, typename... _ArgTypes> | |
411 | struct is_function<_Res(_ArgTypes......) &&> | |
412 | : public true_type { }; | |
413 | ||
53dc5044 PC |
414 | template<typename _Res, typename... _ArgTypes> |
415 | struct is_function<_Res(_ArgTypes...) const> | |
416 | : public true_type { }; | |
123c516a | 417 | |
89898034 DK |
418 | template<typename _Res, typename... _ArgTypes> |
419 | struct is_function<_Res(_ArgTypes...) const &> | |
420 | : public true_type { }; | |
421 | ||
422 | template<typename _Res, typename... _ArgTypes> | |
423 | struct is_function<_Res(_ArgTypes...) const &&> | |
424 | : public true_type { }; | |
425 | ||
53dc5044 PC |
426 | template<typename _Res, typename... _ArgTypes> |
427 | struct is_function<_Res(_ArgTypes......) const> | |
428 | : public true_type { }; | |
123c516a | 429 | |
89898034 DK |
430 | template<typename _Res, typename... _ArgTypes> |
431 | struct is_function<_Res(_ArgTypes......) const &> | |
432 | : public true_type { }; | |
433 | ||
434 | template<typename _Res, typename... _ArgTypes> | |
435 | struct is_function<_Res(_ArgTypes......) const &&> | |
436 | : public true_type { }; | |
437 | ||
53dc5044 PC |
438 | template<typename _Res, typename... _ArgTypes> |
439 | struct is_function<_Res(_ArgTypes...) volatile> | |
440 | : public true_type { }; | |
123c516a | 441 | |
89898034 DK |
442 | template<typename _Res, typename... _ArgTypes> |
443 | struct is_function<_Res(_ArgTypes...) volatile &> | |
444 | : public true_type { }; | |
445 | ||
446 | template<typename _Res, typename... _ArgTypes> | |
447 | struct is_function<_Res(_ArgTypes...) volatile &&> | |
448 | : public true_type { }; | |
449 | ||
53dc5044 PC |
450 | template<typename _Res, typename... _ArgTypes> |
451 | struct is_function<_Res(_ArgTypes......) volatile> | |
452 | : public true_type { }; | |
123c516a | 453 | |
89898034 DK |
454 | template<typename _Res, typename... _ArgTypes> |
455 | struct is_function<_Res(_ArgTypes......) volatile &> | |
456 | : public true_type { }; | |
457 | ||
458 | template<typename _Res, typename... _ArgTypes> | |
459 | struct is_function<_Res(_ArgTypes......) volatile &&> | |
460 | : public true_type { }; | |
461 | ||
53dc5044 PC |
462 | template<typename _Res, typename... _ArgTypes> |
463 | struct is_function<_Res(_ArgTypes...) const volatile> | |
464 | : public true_type { }; | |
123c516a | 465 | |
89898034 DK |
466 | template<typename _Res, typename... _ArgTypes> |
467 | struct is_function<_Res(_ArgTypes...) const volatile &> | |
468 | : public true_type { }; | |
469 | ||
470 | template<typename _Res, typename... _ArgTypes> | |
471 | struct is_function<_Res(_ArgTypes...) const volatile &&> | |
472 | : public true_type { }; | |
473 | ||
53dc5044 PC |
474 | template<typename _Res, typename... _ArgTypes> |
475 | struct is_function<_Res(_ArgTypes......) const volatile> | |
476 | : public true_type { }; | |
477 | ||
89898034 DK |
478 | template<typename _Res, typename... _ArgTypes> |
479 | struct is_function<_Res(_ArgTypes......) const volatile &> | |
480 | : public true_type { }; | |
481 | ||
482 | template<typename _Res, typename... _ArgTypes> | |
483 | struct is_function<_Res(_ArgTypes......) const volatile &&> | |
484 | : public true_type { }; | |
485 | ||
a15f7cb8 ESR |
486 | #define __cpp_lib_is_null_pointer 201309 |
487 | ||
1e673415 | 488 | template<typename> |
aa940ab5 | 489 | struct __is_null_pointer_helper |
1e673415 | 490 | : public false_type { }; |
123c516a PC |
491 | |
492 | template<> | |
aa940ab5 | 493 | struct __is_null_pointer_helper<std::nullptr_t> |
123c516a | 494 | : public true_type { }; |
1e673415 | 495 | |
aa940ab5 PC |
496 | /// is_null_pointer (LWG 2247). |
497 | template<typename _Tp> | |
498 | struct is_null_pointer | |
499 | : public __is_null_pointer_helper<typename remove_cv<_Tp>::type>::type | |
500 | { }; | |
501 | ||
502 | /// __is_nullptr_t (extension). | |
1e673415 PC |
503 | template<typename _Tp> |
504 | struct __is_nullptr_t | |
aa940ab5 | 505 | : public is_null_pointer<_Tp> |
1e673415 PC |
506 | { }; |
507 | ||
c0ffa2ba | 508 | // Composite type categories. |
123c516a PC |
509 | |
510 | /// is_reference | |
511 | template<typename _Tp> | |
512 | struct is_reference | |
513 | : public __or_<is_lvalue_reference<_Tp>, | |
514 | is_rvalue_reference<_Tp>>::type | |
515 | { }; | |
516 | ||
53dc5044 PC |
517 | /// is_arithmetic |
518 | template<typename _Tp> | |
519 | struct is_arithmetic | |
123c516a | 520 | : public __or_<is_integral<_Tp>, is_floating_point<_Tp>>::type |
53dc5044 PC |
521 | { }; |
522 | ||
523 | /// is_fundamental | |
524 | template<typename _Tp> | |
525 | struct is_fundamental | |
aa940ab5 PC |
526 | : public __or_<is_arithmetic<_Tp>, is_void<_Tp>, |
527 | is_null_pointer<_Tp>>::type | |
53dc5044 PC |
528 | { }; |
529 | ||
530 | /// is_object | |
531 | template<typename _Tp> | |
532 | struct is_object | |
123c516a PC |
533 | : public __not_<__or_<is_function<_Tp>, is_reference<_Tp>, |
534 | is_void<_Tp>>>::type | |
53dc5044 PC |
535 | { }; |
536 | ||
123c516a | 537 | template<typename> |
53dc5044 PC |
538 | struct is_member_pointer; |
539 | ||
540 | /// is_scalar | |
541 | template<typename _Tp> | |
542 | struct is_scalar | |
123c516a | 543 | : public __or_<is_arithmetic<_Tp>, is_enum<_Tp>, is_pointer<_Tp>, |
aa940ab5 | 544 | is_member_pointer<_Tp>, is_null_pointer<_Tp>>::type |
53dc5044 PC |
545 | { }; |
546 | ||
547 | /// is_compound | |
548 | template<typename _Tp> | |
549 | struct is_compound | |
550 | : public integral_constant<bool, !is_fundamental<_Tp>::value> { }; | |
551 | ||
53dc5044 PC |
552 | template<typename _Tp> |
553 | struct __is_member_pointer_helper | |
554 | : public false_type { }; | |
123c516a PC |
555 | |
556 | template<typename _Tp, typename _Cp> | |
557 | struct __is_member_pointer_helper<_Tp _Cp::*> | |
558 | : public true_type { }; | |
53dc5044 | 559 | |
13901e4b | 560 | /// is_member_pointer |
53dc5044 | 561 | template<typename _Tp> |
123c516a | 562 | struct is_member_pointer |
82b12c4b | 563 | : public __is_member_pointer_helper<typename remove_cv<_Tp>::type>::type |
53dc5044 PC |
564 | { }; |
565 | ||
89898034 DK |
566 | // Utility to detect referenceable types ([defns.referenceable]). |
567 | ||
568 | template<typename _Tp> | |
569 | struct __is_referenceable | |
570 | : public __or_<is_object<_Tp>, is_reference<_Tp>>::type | |
571 | { }; | |
572 | ||
573 | template<typename _Res, typename... _Args> | |
574 | struct __is_referenceable<_Res(_Args...)> | |
575 | : public true_type | |
576 | { }; | |
577 | ||
578 | template<typename _Res, typename... _Args> | |
579 | struct __is_referenceable<_Res(_Args......)> | |
580 | : public true_type | |
581 | { }; | |
582 | ||
c0ffa2ba | 583 | // Type properties. |
123c516a | 584 | |
53dc5044 PC |
585 | /// is_const |
586 | template<typename> | |
587 | struct is_const | |
588 | : public false_type { }; | |
589 | ||
590 | template<typename _Tp> | |
591 | struct is_const<_Tp const> | |
592 | : public true_type { }; | |
593 | ||
594 | /// is_volatile | |
595 | template<typename> | |
596 | struct is_volatile | |
597 | : public false_type { }; | |
598 | ||
599 | template<typename _Tp> | |
600 | struct is_volatile<_Tp volatile> | |
601 | : public true_type { }; | |
602 | ||
123c516a PC |
603 | /// is_trivial |
604 | template<typename _Tp> | |
605 | struct is_trivial | |
606 | : public integral_constant<bool, __is_trivial(_Tp)> | |
607 | { }; | |
608 | ||
f5e523b7 VV |
609 | // is_trivially_copyable |
610 | template<typename _Tp> | |
611 | struct is_trivially_copyable | |
612 | : public integral_constant<bool, __is_trivially_copyable(_Tp)> | |
613 | { }; | |
123c516a PC |
614 | |
615 | /// is_standard_layout | |
616 | template<typename _Tp> | |
617 | struct is_standard_layout | |
618 | : public integral_constant<bool, __is_standard_layout(_Tp)> | |
619 | { }; | |
620 | ||
621 | /// is_pod | |
622 | // Could use is_standard_layout && is_trivial instead of the builtin. | |
623 | template<typename _Tp> | |
624 | struct is_pod | |
625 | : public integral_constant<bool, __is_pod(_Tp)> | |
626 | { }; | |
627 | ||
628 | /// is_literal_type | |
629 | template<typename _Tp> | |
630 | struct is_literal_type | |
631 | : public integral_constant<bool, __is_literal_type(_Tp)> | |
632 | { }; | |
633 | ||
53dc5044 PC |
634 | /// is_empty |
635 | template<typename _Tp> | |
636 | struct is_empty | |
637 | : public integral_constant<bool, __is_empty(_Tp)> | |
638 | { }; | |
639 | ||
640 | /// is_polymorphic | |
641 | template<typename _Tp> | |
642 | struct is_polymorphic | |
643 | : public integral_constant<bool, __is_polymorphic(_Tp)> | |
644 | { }; | |
645 | ||
4db7fcb9 ESR |
646 | #if __cplusplus >= 201402L |
647 | #define __cpp_lib_is_final 201402L | |
648 | /// is_final | |
649 | template<typename _Tp> | |
650 | struct is_final | |
651 | : public integral_constant<bool, __is_final(_Tp)> | |
652 | { }; | |
653 | #endif | |
654 | ||
53dc5044 PC |
655 | /// is_abstract |
656 | template<typename _Tp> | |
657 | struct is_abstract | |
658 | : public integral_constant<bool, __is_abstract(_Tp)> | |
659 | { }; | |
660 | ||
123c516a | 661 | template<typename _Tp, |
6a4b1a00 | 662 | bool = is_arithmetic<_Tp>::value> |
123c516a PC |
663 | struct __is_signed_helper |
664 | : public false_type { }; | |
665 | ||
53dc5044 | 666 | template<typename _Tp> |
6a4b1a00 PC |
667 | struct __is_signed_helper<_Tp, true> |
668 | : public integral_constant<bool, _Tp(-1) < _Tp(0)> | |
53dc5044 PC |
669 | { }; |
670 | ||
123c516a | 671 | /// is_signed |
53dc5044 | 672 | template<typename _Tp> |
123c516a | 673 | struct is_signed |
82b12c4b | 674 | : public __is_signed_helper<_Tp>::type |
123c516a PC |
675 | { }; |
676 | ||
677 | /// is_unsigned | |
678 | template<typename _Tp> | |
679 | struct is_unsigned | |
680 | : public __and_<is_arithmetic<_Tp>, __not_<is_signed<_Tp>>>::type | |
681 | { }; | |
682 | ||
683 | ||
c0ffa2ba | 684 | // Destructible and constructible type properties. |
123c516a | 685 | |
53dc5044 | 686 | template<typename> |
123c516a | 687 | struct add_rvalue_reference; |
53dc5044 | 688 | |
13901e4b JW |
689 | /** |
690 | * @brief Utility to simplify expressions used in unevaluated operands | |
691 | * @ingroup utilities | |
692 | */ | |
53dc5044 | 693 | template<typename _Tp> |
123c516a | 694 | typename add_rvalue_reference<_Tp>::type declval() noexcept; |
53dc5044 | 695 | |
123c516a PC |
696 | template<typename, unsigned = 0> |
697 | struct extent; | |
698 | ||
699 | template<typename> | |
700 | struct remove_all_extents; | |
701 | ||
702 | template<typename _Tp> | |
703 | struct __is_array_known_bounds | |
704 | : public integral_constant<bool, (extent<_Tp>::value > 0)> | |
53dc5044 PC |
705 | { }; |
706 | ||
123c516a PC |
707 | template<typename _Tp> |
708 | struct __is_array_unknown_bounds | |
709 | : public __and_<is_array<_Tp>, __not_<extent<_Tp>>>::type | |
53dc5044 | 710 | { }; |
2c7a09d7 | 711 | |
62fa805f | 712 | // In N3290 is_destructible does not say anything about function |
2c7a09d7 | 713 | // types and abstract types, see LWG 2049. This implementation |
62fa805f DK |
714 | // describes function types as non-destructible and all complete |
715 | // object types as destructible, iff the explicit destructor | |
2c7a09d7 | 716 | // call expression is wellformed. |
62fa805f | 717 | struct __do_is_destructible_impl |
123c516a | 718 | { |
62fa805f | 719 | template<typename _Tp, typename = decltype(declval<_Tp&>().~_Tp())> |
123c516a PC |
720 | static true_type __test(int); |
721 | ||
722 | template<typename> | |
723 | static false_type __test(...); | |
724 | }; | |
53dc5044 PC |
725 | |
726 | template<typename _Tp> | |
62fa805f DK |
727 | struct __is_destructible_impl |
728 | : public __do_is_destructible_impl | |
123c516a PC |
729 | { |
730 | typedef decltype(__test<_Tp>(0)) type; | |
731 | }; | |
53dc5044 | 732 | |
62fa805f DK |
733 | template<typename _Tp, |
734 | bool = __or_<is_void<_Tp>, | |
735 | __is_array_unknown_bounds<_Tp>, | |
736 | is_function<_Tp>>::value, | |
737 | bool = __or_<is_reference<_Tp>, is_scalar<_Tp>>::value> | |
738 | struct __is_destructible_safe; | |
739 | ||
740 | template<typename _Tp> | |
741 | struct __is_destructible_safe<_Tp, false, false> | |
742 | : public __is_destructible_impl<typename | |
743 | remove_all_extents<_Tp>::type>::type | |
744 | { }; | |
745 | ||
746 | template<typename _Tp> | |
747 | struct __is_destructible_safe<_Tp, true, false> | |
748 | : public false_type { }; | |
749 | ||
750 | template<typename _Tp> | |
751 | struct __is_destructible_safe<_Tp, false, true> | |
752 | : public true_type { }; | |
753 | ||
754 | /// is_destructible | |
755 | template<typename _Tp> | |
756 | struct is_destructible | |
82b12c4b | 757 | : public __is_destructible_safe<_Tp>::type |
62fa805f DK |
758 | { }; |
759 | ||
760 | // is_nothrow_destructible requires that is_destructible is | |
761 | // satisfied as well. We realize that by mimicing the | |
762 | // implementation of is_destructible but refer to noexcept(expr) | |
763 | // instead of decltype(expr). | |
764 | struct __do_is_nt_destructible_impl | |
123c516a | 765 | { |
62fa805f DK |
766 | template<typename _Tp> |
767 | static integral_constant<bool, noexcept(declval<_Tp&>().~_Tp())> | |
768 | __test(int); | |
123c516a PC |
769 | |
770 | template<typename> | |
771 | static false_type __test(...); | |
772 | }; | |
53dc5044 | 773 | |
53dc5044 | 774 | template<typename _Tp> |
62fa805f DK |
775 | struct __is_nt_destructible_impl |
776 | : public __do_is_nt_destructible_impl | |
123c516a PC |
777 | { |
778 | typedef decltype(__test<_Tp>(0)) type; | |
779 | }; | |
780 | ||
781 | template<typename _Tp, | |
782 | bool = __or_<is_void<_Tp>, | |
62fa805f DK |
783 | __is_array_unknown_bounds<_Tp>, |
784 | is_function<_Tp>>::value, | |
785 | bool = __or_<is_reference<_Tp>, is_scalar<_Tp>>::value> | |
786 | struct __is_nt_destructible_safe; | |
53dc5044 PC |
787 | |
788 | template<typename _Tp> | |
62fa805f DK |
789 | struct __is_nt_destructible_safe<_Tp, false, false> |
790 | : public __is_nt_destructible_impl<typename | |
791 | remove_all_extents<_Tp>::type>::type | |
123c516a PC |
792 | { }; |
793 | ||
53dc5044 | 794 | template<typename _Tp> |
62fa805f | 795 | struct __is_nt_destructible_safe<_Tp, true, false> |
123c516a | 796 | : public false_type { }; |
53dc5044 PC |
797 | |
798 | template<typename _Tp> | |
62fa805f | 799 | struct __is_nt_destructible_safe<_Tp, false, true> |
123c516a PC |
800 | : public true_type { }; |
801 | ||
62fa805f | 802 | /// is_nothrow_destructible |
53dc5044 | 803 | template<typename _Tp> |
62fa805f | 804 | struct is_nothrow_destructible |
82b12c4b | 805 | : public __is_nt_destructible_safe<_Tp>::type |
123c516a PC |
806 | { }; |
807 | ||
808 | struct __do_is_default_constructible_impl | |
809 | { | |
810 | template<typename _Tp, typename = decltype(_Tp())> | |
811 | static true_type __test(int); | |
812 | ||
813 | template<typename> | |
814 | static false_type __test(...); | |
815 | }; | |
816 | ||
817 | template<typename _Tp> | |
818 | struct __is_default_constructible_impl | |
819 | : public __do_is_default_constructible_impl | |
53dc5044 | 820 | { |
123c516a | 821 | typedef decltype(__test<_Tp>(0)) type; |
53dc5044 | 822 | }; |
53dc5044 PC |
823 | |
824 | template<typename _Tp> | |
123c516a | 825 | struct __is_default_constructible_atom |
2c7a09d7 PC |
826 | : public __and_<__not_<is_void<_Tp>>, |
827 | __is_default_constructible_impl<_Tp>>::type | |
123c516a | 828 | { }; |
53dc5044 | 829 | |
123c516a PC |
830 | template<typename _Tp, bool = is_array<_Tp>::value> |
831 | struct __is_default_constructible_safe; | |
53dc5044 | 832 | |
2c7a09d7 PC |
833 | // The following technique is a workaround for a current core language |
834 | // restriction, which does not allow for array types to occur in | |
835 | // functional casts of the form T(). Complete arrays can be default- | |
836 | // constructed, if the element type is default-constructible, but | |
837 | // arrays with unknown bounds are not. | |
53dc5044 | 838 | template<typename _Tp> |
123c516a PC |
839 | struct __is_default_constructible_safe<_Tp, true> |
840 | : public __and_<__is_array_known_bounds<_Tp>, | |
841 | __is_default_constructible_atom<typename | |
2c7a09d7 | 842 | remove_all_extents<_Tp>::type>>::type |
53dc5044 PC |
843 | { }; |
844 | ||
53dc5044 | 845 | template<typename _Tp> |
123c516a PC |
846 | struct __is_default_constructible_safe<_Tp, false> |
847 | : public __is_default_constructible_atom<_Tp>::type | |
848 | { }; | |
4a27a739 | 849 | |
123c516a | 850 | /// is_default_constructible |
4a27a739 | 851 | template<typename _Tp> |
123c516a | 852 | struct is_default_constructible |
82b12c4b | 853 | : public __is_default_constructible_safe<_Tp>::type |
123c516a | 854 | { }; |
4a27a739 | 855 | |
2c7a09d7 PC |
856 | |
857 | // Implementation of is_constructible. | |
858 | ||
859 | // The hardest part of this trait is the binary direct-initialization | |
860 | // case, because we hit into a functional cast of the form T(arg). | |
861 | // This implementation uses different strategies depending on the | |
862 | // target type to reduce the test overhead as much as possible: | |
863 | // | |
864 | // a) For a reference target type, we use a static_cast expression | |
865 | // modulo its extra cases. | |
866 | // | |
867 | // b) For a non-reference target type we use a ::new expression. | |
123c516a PC |
868 | struct __do_is_static_castable_impl |
869 | { | |
870 | template<typename _From, typename _To, typename | |
871 | = decltype(static_cast<_To>(declval<_From>()))> | |
872 | static true_type __test(int); | |
4a27a739 | 873 | |
123c516a PC |
874 | template<typename, typename> |
875 | static false_type __test(...); | |
876 | }; | |
4a27a739 | 877 | |
123c516a PC |
878 | template<typename _From, typename _To> |
879 | struct __is_static_castable_impl | |
880 | : public __do_is_static_castable_impl | |
881 | { | |
882 | typedef decltype(__test<_From, _To>(0)) type; | |
883 | }; | |
939759fc | 884 | |
123c516a PC |
885 | template<typename _From, typename _To> |
886 | struct __is_static_castable_safe | |
2c7a09d7 | 887 | : public __is_static_castable_impl<_From, _To>::type |
4a27a739 PC |
888 | { }; |
889 | ||
123c516a PC |
890 | // __is_static_castable |
891 | template<typename _From, typename _To> | |
892 | struct __is_static_castable | |
893 | : public integral_constant<bool, (__is_static_castable_safe< | |
894 | _From, _To>::value)> | |
895 | { }; | |
939759fc | 896 | |
2c7a09d7 PC |
897 | // Implementation for non-reference types. To meet the proper |
898 | // variable definition semantics, we also need to test for | |
899 | // is_destructible in this case. | |
5db25ab1 DK |
900 | // This form should be simplified by a single expression: |
901 | // ::delete ::new _Tp(declval<_Arg>()), see c++/51222. | |
123c516a PC |
902 | struct __do_is_direct_constructible_impl |
903 | { | |
904 | template<typename _Tp, typename _Arg, typename | |
905 | = decltype(::new _Tp(declval<_Arg>()))> | |
906 | static true_type __test(int); | |
4a27a739 | 907 | |
123c516a PC |
908 | template<typename, typename> |
909 | static false_type __test(...); | |
910 | }; | |
4a27a739 | 911 | |
123c516a PC |
912 | template<typename _Tp, typename _Arg> |
913 | struct __is_direct_constructible_impl | |
914 | : public __do_is_direct_constructible_impl | |
915 | { | |
916 | typedef decltype(__test<_Tp, _Arg>(0)) type; | |
917 | }; | |
4a27a739 | 918 | |
123c516a PC |
919 | template<typename _Tp, typename _Arg> |
920 | struct __is_direct_constructible_new_safe | |
921 | : public __and_<is_destructible<_Tp>, | |
2c7a09d7 | 922 | __is_direct_constructible_impl<_Tp, _Arg>>::type |
123c516a | 923 | { }; |
4a27a739 | 924 | |
123c516a PC |
925 | template<typename, typename> |
926 | struct is_same; | |
4a27a739 | 927 | |
123c516a PC |
928 | template<typename, typename> |
929 | struct is_base_of; | |
4a27a739 | 930 | |
123c516a PC |
931 | template<typename> |
932 | struct remove_reference; | |
4a27a739 | 933 | |
123c516a | 934 | template<typename _From, typename _To, bool |
5db25ab1 DK |
935 | = __not_<__or_<is_void<_From>, |
936 | is_function<_From>>>::value> | |
123c516a | 937 | struct __is_base_to_derived_ref; |
4a27a739 | 938 | |
5db25ab1 DK |
939 | // Detect whether we have a downcast situation during |
940 | // reference binding. | |
123c516a PC |
941 | template<typename _From, typename _To> |
942 | struct __is_base_to_derived_ref<_From, _To, true> | |
943 | { | |
944 | typedef typename remove_cv<typename remove_reference<_From | |
945 | >::type>::type __src_t; | |
946 | typedef typename remove_cv<typename remove_reference<_To | |
947 | >::type>::type __dst_t; | |
2c7a09d7 PC |
948 | typedef __and_<__not_<is_same<__src_t, __dst_t>>, |
949 | is_base_of<__src_t, __dst_t>> type; | |
123c516a PC |
950 | static constexpr bool value = type::value; |
951 | }; | |
4a27a739 | 952 | |
123c516a PC |
953 | template<typename _From, typename _To> |
954 | struct __is_base_to_derived_ref<_From, _To, false> | |
955 | : public false_type | |
4a27a739 PC |
956 | { }; |
957 | ||
123c516a PC |
958 | template<typename _From, typename _To, bool |
959 | = __and_<is_lvalue_reference<_From>, | |
960 | is_rvalue_reference<_To>>::value> | |
961 | struct __is_lvalue_to_rvalue_ref; | |
e133ace8 | 962 | |
5db25ab1 DK |
963 | // Detect whether we have an lvalue of non-function type |
964 | // bound to a reference-compatible rvalue-reference. | |
123c516a PC |
965 | template<typename _From, typename _To> |
966 | struct __is_lvalue_to_rvalue_ref<_From, _To, true> | |
967 | { | |
968 | typedef typename remove_cv<typename remove_reference< | |
969 | _From>::type>::type __src_t; | |
970 | typedef typename remove_cv<typename remove_reference< | |
971 | _To>::type>::type __dst_t; | |
5db25ab1 DK |
972 | typedef __and_<__not_<is_function<__src_t>>, |
973 | __or_<is_same<__src_t, __dst_t>, | |
974 | is_base_of<__dst_t, __src_t>>> type; | |
123c516a PC |
975 | static constexpr bool value = type::value; |
976 | }; | |
e133ace8 | 977 | |
123c516a PC |
978 | template<typename _From, typename _To> |
979 | struct __is_lvalue_to_rvalue_ref<_From, _To, false> | |
980 | : public false_type | |
e133ace8 PC |
981 | { }; |
982 | ||
2c7a09d7 PC |
983 | // Here we handle direct-initialization to a reference type as |
984 | // equivalent to a static_cast modulo overshooting conversions. | |
985 | // These are restricted to the following conversions: | |
5db25ab1 | 986 | // a) A base class value to a derived class reference |
2c7a09d7 | 987 | // b) An lvalue to an rvalue-reference of reference-compatible |
5db25ab1 | 988 | // types that are not functions |
123c516a PC |
989 | template<typename _Tp, typename _Arg> |
990 | struct __is_direct_constructible_ref_cast | |
991 | : public __and_<__is_static_castable<_Arg, _Tp>, | |
992 | __not_<__or_<__is_base_to_derived_ref<_Arg, _Tp>, | |
993 | __is_lvalue_to_rvalue_ref<_Arg, _Tp> | |
2c7a09d7 | 994 | >>>::type |
e133ace8 PC |
995 | { }; |
996 | ||
123c516a PC |
997 | template<typename _Tp, typename _Arg> |
998 | struct __is_direct_constructible_new | |
999 | : public conditional<is_reference<_Tp>::value, | |
1000 | __is_direct_constructible_ref_cast<_Tp, _Arg>, | |
1001 | __is_direct_constructible_new_safe<_Tp, _Arg> | |
1002 | >::type | |
b0302c68 PC |
1003 | { }; |
1004 | ||
123c516a PC |
1005 | template<typename _Tp, typename _Arg> |
1006 | struct __is_direct_constructible | |
82b12c4b | 1007 | : public __is_direct_constructible_new<_Tp, _Arg>::type |
e133ace8 PC |
1008 | { }; |
1009 | ||
2c7a09d7 PC |
1010 | // Since default-construction and binary direct-initialization have |
1011 | // been handled separately, the implementation of the remaining | |
5db25ab1 DK |
1012 | // n-ary construction cases is rather straightforward. We can use |
1013 | // here a functional cast, because array types are excluded anyway | |
1014 | // and this form is never interpreted as a C cast. | |
123c516a PC |
1015 | struct __do_is_nary_constructible_impl |
1016 | { | |
1017 | template<typename _Tp, typename... _Args, typename | |
1018 | = decltype(_Tp(declval<_Args>()...))> | |
1019 | static true_type __test(int); | |
2b08f2c5 | 1020 | |
123c516a PC |
1021 | template<typename, typename...> |
1022 | static false_type __test(...); | |
1023 | }; | |
b0302c68 PC |
1024 | |
1025 | template<typename _Tp, typename... _Args> | |
123c516a PC |
1026 | struct __is_nary_constructible_impl |
1027 | : public __do_is_nary_constructible_impl | |
b0302c68 | 1028 | { |
123c516a | 1029 | typedef decltype(__test<_Tp, _Args...>(0)) type; |
b0302c68 PC |
1030 | }; |
1031 | ||
123c516a PC |
1032 | template<typename _Tp, typename... _Args> |
1033 | struct __is_nary_constructible | |
2c7a09d7 | 1034 | : public __is_nary_constructible_impl<_Tp, _Args...>::type |
b0302c68 | 1035 | { |
123c516a PC |
1036 | static_assert(sizeof...(_Args) > 1, |
1037 | "Only useful for > 1 arguments"); | |
1038 | }; | |
b0302c68 | 1039 | |
123c516a PC |
1040 | template<typename _Tp, typename... _Args> |
1041 | struct __is_constructible_impl | |
1042 | : public __is_nary_constructible<_Tp, _Args...> | |
1043 | { }; | |
b0302c68 | 1044 | |
123c516a PC |
1045 | template<typename _Tp, typename _Arg> |
1046 | struct __is_constructible_impl<_Tp, _Arg> | |
1047 | : public __is_direct_constructible<_Tp, _Arg> | |
1048 | { }; | |
1049 | ||
1050 | template<typename _Tp> | |
1051 | struct __is_constructible_impl<_Tp> | |
1052 | : public is_default_constructible<_Tp> | |
1053 | { }; | |
b0302c68 PC |
1054 | |
1055 | /// is_constructible | |
b0302c68 PC |
1056 | template<typename _Tp, typename... _Args> |
1057 | struct is_constructible | |
82b12c4b | 1058 | : public __is_constructible_impl<_Tp, _Args...>::type |
c32097d8 JM |
1059 | { }; |
1060 | ||
89898034 | 1061 | template<typename _Tp, bool = __is_referenceable<_Tp>::value> |
65cee9bd | 1062 | struct __is_copy_constructible_impl; |
123c516a | 1063 | |
65cee9bd | 1064 | template<typename _Tp> |
89898034 | 1065 | struct __is_copy_constructible_impl<_Tp, false> |
65cee9bd PC |
1066 | : public false_type { }; |
1067 | ||
1068 | template<typename _Tp> | |
89898034 | 1069 | struct __is_copy_constructible_impl<_Tp, true> |
65cee9bd PC |
1070 | : public is_constructible<_Tp, const _Tp&> |
1071 | { }; | |
1072 | ||
1073 | /// is_copy_constructible | |
1074 | template<typename _Tp> | |
1075 | struct is_copy_constructible | |
1076 | : public __is_copy_constructible_impl<_Tp> | |
1077 | { }; | |
1078 | ||
89898034 | 1079 | template<typename _Tp, bool = __is_referenceable<_Tp>::value> |
65cee9bd PC |
1080 | struct __is_move_constructible_impl; |
1081 | ||
1082 | template<typename _Tp> | |
89898034 | 1083 | struct __is_move_constructible_impl<_Tp, false> |
65cee9bd PC |
1084 | : public false_type { }; |
1085 | ||
1086 | template<typename _Tp> | |
89898034 | 1087 | struct __is_move_constructible_impl<_Tp, true> |
65cee9bd PC |
1088 | : public is_constructible<_Tp, _Tp&&> |
1089 | { }; | |
1090 | ||
1091 | /// is_move_constructible | |
1092 | template<typename _Tp> | |
1093 | struct is_move_constructible | |
1094 | : public __is_move_constructible_impl<_Tp> | |
1095 | { }; | |
1096 | ||
1097 | template<typename _Tp> | |
1098 | struct __is_nt_default_constructible_atom | |
1099 | : public integral_constant<bool, noexcept(_Tp())> | |
1100 | { }; | |
1101 | ||
1102 | template<typename _Tp, bool = is_array<_Tp>::value> | |
1103 | struct __is_nt_default_constructible_impl; | |
1104 | ||
1105 | template<typename _Tp> | |
1106 | struct __is_nt_default_constructible_impl<_Tp, true> | |
1107 | : public __and_<__is_array_known_bounds<_Tp>, | |
1108 | __is_nt_default_constructible_atom<typename | |
1109 | remove_all_extents<_Tp>::type>>::type | |
1110 | { }; | |
1111 | ||
1112 | template<typename _Tp> | |
1113 | struct __is_nt_default_constructible_impl<_Tp, false> | |
1114 | : public __is_nt_default_constructible_atom<_Tp> | |
1115 | { }; | |
1116 | ||
1117 | /// is_nothrow_default_constructible | |
1118 | template<typename _Tp> | |
1119 | struct is_nothrow_default_constructible | |
1120 | : public __and_<is_default_constructible<_Tp>, | |
1121 | __is_nt_default_constructible_impl<_Tp>>::type | |
1122 | { }; | |
e4f32cb0 PC |
1123 | |
1124 | template<typename _Tp, typename... _Args> | |
65cee9bd PC |
1125 | struct __is_nt_constructible_impl |
1126 | : public integral_constant<bool, noexcept(_Tp(declval<_Args>()...))> | |
1127 | { }; | |
e4f32cb0 PC |
1128 | |
1129 | template<typename _Tp, typename _Arg> | |
65cee9bd PC |
1130 | struct __is_nt_constructible_impl<_Tp, _Arg> |
1131 | : public integral_constant<bool, | |
1132 | noexcept(static_cast<_Tp>(declval<_Arg>()))> | |
1133 | { }; | |
1134 | ||
1135 | template<typename _Tp> | |
1136 | struct __is_nt_constructible_impl<_Tp> | |
1137 | : public is_nothrow_default_constructible<_Tp> | |
1138 | { }; | |
e4f32cb0 PC |
1139 | |
1140 | /// is_nothrow_constructible | |
1141 | template<typename _Tp, typename... _Args> | |
1142 | struct is_nothrow_constructible | |
65cee9bd PC |
1143 | : public __and_<is_constructible<_Tp, _Args...>, |
1144 | __is_nt_constructible_impl<_Tp, _Args...>>::type | |
1145 | { }; | |
1146 | ||
89898034 | 1147 | template<typename _Tp, bool = __is_referenceable<_Tp>::value> |
65cee9bd PC |
1148 | struct __is_nothrow_copy_constructible_impl; |
1149 | ||
1150 | template<typename _Tp> | |
89898034 | 1151 | struct __is_nothrow_copy_constructible_impl<_Tp, false> |
65cee9bd PC |
1152 | : public false_type { }; |
1153 | ||
1154 | template<typename _Tp> | |
89898034 | 1155 | struct __is_nothrow_copy_constructible_impl<_Tp, true> |
65cee9bd PC |
1156 | : public is_nothrow_constructible<_Tp, const _Tp&> |
1157 | { }; | |
1158 | ||
1159 | /// is_nothrow_copy_constructible | |
1160 | template<typename _Tp> | |
1161 | struct is_nothrow_copy_constructible | |
1162 | : public __is_nothrow_copy_constructible_impl<_Tp> | |
1163 | { }; | |
1164 | ||
89898034 | 1165 | template<typename _Tp, bool = __is_referenceable<_Tp>::value> |
65cee9bd PC |
1166 | struct __is_nothrow_move_constructible_impl; |
1167 | ||
1168 | template<typename _Tp> | |
89898034 | 1169 | struct __is_nothrow_move_constructible_impl<_Tp, false> |
65cee9bd PC |
1170 | : public false_type { }; |
1171 | ||
1172 | template<typename _Tp> | |
89898034 | 1173 | struct __is_nothrow_move_constructible_impl<_Tp, true> |
65cee9bd PC |
1174 | : public is_nothrow_constructible<_Tp, _Tp&&> |
1175 | { }; | |
1176 | ||
1177 | /// is_nothrow_move_constructible | |
1178 | template<typename _Tp> | |
1179 | struct is_nothrow_move_constructible | |
1180 | : public __is_nothrow_move_constructible_impl<_Tp> | |
1181 | { }; | |
1182 | ||
f263981a PC |
1183 | template<typename _Tp, typename _Up> |
1184 | class __is_assignable_helper | |
f263981a | 1185 | { |
82b12c4b FD |
1186 | template<typename _Tp1, typename _Up1, |
1187 | typename = decltype(declval<_Tp1>() = declval<_Up1>())> | |
1188 | static true_type | |
f263981a PC |
1189 | __test(int); |
1190 | ||
1191 | template<typename, typename> | |
82b12c4b FD |
1192 | static false_type |
1193 | __test(...); | |
f263981a PC |
1194 | |
1195 | public: | |
82b12c4b | 1196 | typedef decltype(__test<_Tp, _Up>(0)) type; |
f263981a PC |
1197 | }; |
1198 | ||
1199 | /// is_assignable | |
1200 | template<typename _Tp, typename _Up> | |
1201 | struct is_assignable | |
82b12c4b | 1202 | : public __is_assignable_helper<_Tp, _Up>::type |
f263981a PC |
1203 | { }; |
1204 | ||
89898034 | 1205 | template<typename _Tp, bool = __is_referenceable<_Tp>::value> |
f263981a PC |
1206 | struct __is_copy_assignable_impl; |
1207 | ||
1208 | template<typename _Tp> | |
89898034 | 1209 | struct __is_copy_assignable_impl<_Tp, false> |
f263981a PC |
1210 | : public false_type { }; |
1211 | ||
1212 | template<typename _Tp> | |
89898034 | 1213 | struct __is_copy_assignable_impl<_Tp, true> |
9b3a81da | 1214 | : public is_assignable<_Tp&, const _Tp&> |
f263981a PC |
1215 | { }; |
1216 | ||
1217 | /// is_copy_assignable | |
1218 | template<typename _Tp> | |
1219 | struct is_copy_assignable | |
1220 | : public __is_copy_assignable_impl<_Tp> | |
1221 | { }; | |
1222 | ||
89898034 | 1223 | template<typename _Tp, bool = __is_referenceable<_Tp>::value> |
f263981a PC |
1224 | struct __is_move_assignable_impl; |
1225 | ||
1226 | template<typename _Tp> | |
89898034 | 1227 | struct __is_move_assignable_impl<_Tp, false> |
f263981a PC |
1228 | : public false_type { }; |
1229 | ||
1230 | template<typename _Tp> | |
89898034 | 1231 | struct __is_move_assignable_impl<_Tp, true> |
f263981a PC |
1232 | : public is_assignable<_Tp&, _Tp&&> |
1233 | { }; | |
1234 | ||
1235 | /// is_move_assignable | |
1236 | template<typename _Tp> | |
1237 | struct is_move_assignable | |
1238 | : public __is_move_assignable_impl<_Tp> | |
1239 | { }; | |
1240 | ||
1241 | template<typename _Tp, typename _Up> | |
1242 | struct __is_nt_assignable_impl | |
1243 | : public integral_constant<bool, noexcept(declval<_Tp>() = declval<_Up>())> | |
1244 | { }; | |
1245 | ||
1246 | /// is_nothrow_assignable | |
1247 | template<typename _Tp, typename _Up> | |
1248 | struct is_nothrow_assignable | |
1249 | : public __and_<is_assignable<_Tp, _Up>, | |
1250 | __is_nt_assignable_impl<_Tp, _Up>>::type | |
1251 | { }; | |
1252 | ||
89898034 | 1253 | template<typename _Tp, bool = __is_referenceable<_Tp>::value> |
f263981a PC |
1254 | struct __is_nt_copy_assignable_impl; |
1255 | ||
1256 | template<typename _Tp> | |
89898034 | 1257 | struct __is_nt_copy_assignable_impl<_Tp, false> |
f263981a PC |
1258 | : public false_type { }; |
1259 | ||
1260 | template<typename _Tp> | |
89898034 | 1261 | struct __is_nt_copy_assignable_impl<_Tp, true> |
9b3a81da | 1262 | : public is_nothrow_assignable<_Tp&, const _Tp&> |
f263981a PC |
1263 | { }; |
1264 | ||
1265 | /// is_nothrow_copy_assignable | |
1266 | template<typename _Tp> | |
1267 | struct is_nothrow_copy_assignable | |
1268 | : public __is_nt_copy_assignable_impl<_Tp> | |
1269 | { }; | |
1270 | ||
89898034 | 1271 | template<typename _Tp, bool = __is_referenceable<_Tp>::value> |
f263981a PC |
1272 | struct __is_nt_move_assignable_impl; |
1273 | ||
1274 | template<typename _Tp> | |
89898034 | 1275 | struct __is_nt_move_assignable_impl<_Tp, false> |
f263981a PC |
1276 | : public false_type { }; |
1277 | ||
1278 | template<typename _Tp> | |
89898034 | 1279 | struct __is_nt_move_assignable_impl<_Tp, true> |
f263981a PC |
1280 | : public is_nothrow_assignable<_Tp&, _Tp&&> |
1281 | { }; | |
1282 | ||
1283 | /// is_nothrow_move_assignable | |
65cee9bd | 1284 | template<typename _Tp> |
f263981a PC |
1285 | struct is_nothrow_move_assignable |
1286 | : public __is_nt_move_assignable_impl<_Tp> | |
e4f32cb0 PC |
1287 | { }; |
1288 | ||
f5e523b7 VV |
1289 | /// is_trivially_constructible |
1290 | template<typename _Tp, typename... _Args> | |
1291 | struct is_trivially_constructible | |
1292 | : public __and_<is_constructible<_Tp, _Args...>, integral_constant<bool, | |
1293 | __is_trivially_constructible(_Tp, _Args...)>>::type | |
1294 | { }; | |
6a9ecd34 | 1295 | |
f5e523b7 VV |
1296 | /// is_trivially_default_constructible |
1297 | template<typename _Tp> | |
1298 | struct is_trivially_default_constructible | |
1299 | : public is_trivially_constructible<_Tp>::type | |
1300 | { }; | |
6a9ecd34 | 1301 | |
f5e523b7 VV |
1302 | /// is_trivially_copy_constructible |
1303 | template<typename _Tp> | |
1304 | struct is_trivially_copy_constructible | |
1305 | : public __and_<is_copy_constructible<_Tp>, | |
1306 | integral_constant<bool, | |
1307 | __is_trivially_constructible(_Tp, const _Tp&)>>::type | |
1308 | { }; | |
1309 | ||
1310 | /// is_trivially_move_constructible | |
1311 | template<typename _Tp> | |
1312 | struct is_trivially_move_constructible | |
1313 | : public __and_<is_move_constructible<_Tp>, | |
1314 | integral_constant<bool, | |
1315 | __is_trivially_constructible(_Tp, _Tp&&)>>::type | |
1316 | { }; | |
6a9ecd34 | 1317 | |
f5e523b7 VV |
1318 | /// is_trivially_assignable |
1319 | template<typename _Tp, typename _Up> | |
1320 | struct is_trivially_assignable | |
1321 | : public __and_<is_assignable<_Tp, _Up>, | |
1322 | integral_constant<bool, | |
1323 | __is_trivially_assignable(_Tp, _Up)>>::type | |
1324 | { }; | |
6a9ecd34 | 1325 | |
f5e523b7 VV |
1326 | /// is_trivially_copy_assignable |
1327 | template<typename _Tp> | |
1328 | struct is_trivially_copy_assignable | |
1329 | : public __and_<is_copy_assignable<_Tp>, | |
1330 | integral_constant<bool, | |
1331 | __is_trivially_assignable(_Tp&, const _Tp&)>>::type | |
1332 | { }; | |
6a9ecd34 | 1333 | |
f5e523b7 VV |
1334 | /// is_trivially_move_assignable |
1335 | template<typename _Tp> | |
1336 | struct is_trivially_move_assignable | |
1337 | : public __and_<is_move_assignable<_Tp>, | |
1338 | integral_constant<bool, | |
1339 | __is_trivially_assignable(_Tp&, _Tp&&)>>::type | |
1340 | { }; | |
6a9ecd34 PC |
1341 | |
1342 | /// is_trivially_destructible | |
1343 | template<typename _Tp> | |
1344 | struct is_trivially_destructible | |
1345 | : public __and_<is_destructible<_Tp>, integral_constant<bool, | |
1346 | __has_trivial_destructor(_Tp)>>::type | |
1347 | { }; | |
1348 | ||
1349 | /// has_trivial_default_constructor (temporary legacy) | |
e133ace8 PC |
1350 | template<typename _Tp> |
1351 | struct has_trivial_default_constructor | |
1352 | : public integral_constant<bool, __has_trivial_constructor(_Tp)> | |
1353 | { }; | |
1354 | ||
6a9ecd34 | 1355 | /// has_trivial_copy_constructor (temporary legacy) |
e133ace8 PC |
1356 | template<typename _Tp> |
1357 | struct has_trivial_copy_constructor | |
1358 | : public integral_constant<bool, __has_trivial_copy(_Tp)> | |
1359 | { }; | |
1360 | ||
6a9ecd34 | 1361 | /// has_trivial_copy_assign (temporary legacy) |
e133ace8 | 1362 | template<typename _Tp> |
6f5e9b8d | 1363 | struct has_trivial_copy_assign |
e133ace8 PC |
1364 | : public integral_constant<bool, __has_trivial_assign(_Tp)> |
1365 | { }; | |
1366 | ||
123c516a PC |
1367 | /// has_virtual_destructor |
1368 | template<typename _Tp> | |
1369 | struct has_virtual_destructor | |
1370 | : public integral_constant<bool, __has_virtual_destructor(_Tp)> | |
1371 | { }; | |
1372 | ||
1373 | ||
1374 | // type property queries. | |
1375 | ||
1376 | /// alignment_of | |
1377 | template<typename _Tp> | |
1378 | struct alignment_of | |
1379 | : public integral_constant<std::size_t, __alignof__(_Tp)> { }; | |
1380 | ||
1381 | /// rank | |
1382 | template<typename> | |
1383 | struct rank | |
1384 | : public integral_constant<std::size_t, 0> { }; | |
1385 | ||
1386 | template<typename _Tp, std::size_t _Size> | |
1387 | struct rank<_Tp[_Size]> | |
1388 | : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { }; | |
1389 | ||
1390 | template<typename _Tp> | |
1391 | struct rank<_Tp[]> | |
1392 | : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { }; | |
1393 | ||
1394 | /// extent | |
1395 | template<typename, unsigned _Uint> | |
1396 | struct extent | |
1397 | : public integral_constant<std::size_t, 0> { }; | |
1398 | ||
1399 | template<typename _Tp, unsigned _Uint, std::size_t _Size> | |
1400 | struct extent<_Tp[_Size], _Uint> | |
1401 | : public integral_constant<std::size_t, | |
1402 | _Uint == 0 ? _Size : extent<_Tp, | |
1403 | _Uint - 1>::value> | |
1404 | { }; | |
1405 | ||
1406 | template<typename _Tp, unsigned _Uint> | |
1407 | struct extent<_Tp[], _Uint> | |
1408 | : public integral_constant<std::size_t, | |
1409 | _Uint == 0 ? 0 : extent<_Tp, | |
1410 | _Uint - 1>::value> | |
1411 | { }; | |
1412 | ||
1413 | ||
c0ffa2ba | 1414 | // Type relations. |
123c516a PC |
1415 | |
1416 | /// is_same | |
1417 | template<typename, typename> | |
1418 | struct is_same | |
1419 | : public false_type { }; | |
1420 | ||
1421 | template<typename _Tp> | |
1422 | struct is_same<_Tp, _Tp> | |
1423 | : public true_type { }; | |
b0302c68 | 1424 | |
939759fc | 1425 | /// is_base_of |
e133ace8 PC |
1426 | template<typename _Base, typename _Derived> |
1427 | struct is_base_of | |
1428 | : public integral_constant<bool, __is_base_of(_Base, _Derived)> | |
1429 | { }; | |
1430 | ||
297f34d7 | 1431 | template<typename _From, typename _To, |
123c516a PC |
1432 | bool = __or_<is_void<_From>, is_function<_To>, |
1433 | is_array<_To>>::value> | |
297f34d7 | 1434 | struct __is_convertible_helper |
82b12c4b | 1435 | { typedef typename is_void<_To>::type type; }; |
297f34d7 | 1436 | |
e133ace8 | 1437 | template<typename _From, typename _To> |
b0302c68 | 1438 | class __is_convertible_helper<_From, _To, false> |
e133ace8 | 1439 | { |
82b12c4b FD |
1440 | template<typename _To1> |
1441 | static void __test_aux(_To1); | |
8e7d962a | 1442 | |
82b12c4b FD |
1443 | template<typename _From1, typename _To1, |
1444 | typename = decltype(__test_aux<_To1>(std::declval<_From1>()))> | |
1445 | static true_type | |
8e7d962a PC |
1446 | __test(int); |
1447 | ||
1448 | template<typename, typename> | |
82b12c4b FD |
1449 | static false_type |
1450 | __test(...); | |
297f34d7 | 1451 | |
e133ace8 | 1452 | public: |
82b12c4b | 1453 | typedef decltype(__test<_From, _To>(0)) type; |
e133ace8 PC |
1454 | }; |
1455 | ||
82b12c4b | 1456 | |
b0302c68 | 1457 | /// is_convertible |
e133ace8 PC |
1458 | template<typename _From, typename _To> |
1459 | struct is_convertible | |
82b12c4b | 1460 | : public __is_convertible_helper<_From, _To>::type |
e133ace8 PC |
1461 | { }; |
1462 | ||
fd735b6a | 1463 | |
c0ffa2ba | 1464 | // Const-volatile modifications. |
7b50cdef | 1465 | |
123c516a | 1466 | /// remove_const |
7b50cdef | 1467 | template<typename _Tp> |
123c516a PC |
1468 | struct remove_const |
1469 | { typedef _Tp type; }; | |
7b50cdef | 1470 | |
123c516a PC |
1471 | template<typename _Tp> |
1472 | struct remove_const<_Tp const> | |
1473 | { typedef _Tp type; }; | |
1474 | ||
1475 | /// remove_volatile | |
1476 | template<typename _Tp> | |
1477 | struct remove_volatile | |
1478 | { typedef _Tp type; }; | |
7b50cdef | 1479 | |
123c516a PC |
1480 | template<typename _Tp> |
1481 | struct remove_volatile<_Tp volatile> | |
1482 | { typedef _Tp type; }; | |
1483 | ||
1484 | /// remove_cv | |
1485 | template<typename _Tp> | |
1486 | struct remove_cv | |
1487 | { | |
1488 | typedef typename | |
1489 | remove_const<typename remove_volatile<_Tp>::type>::type type; | |
1490 | }; | |
1491 | ||
1492 | /// add_const | |
1493 | template<typename _Tp> | |
1494 | struct add_const | |
1495 | { typedef _Tp const type; }; | |
1496 | ||
1497 | /// add_volatile | |
1498 | template<typename _Tp> | |
1499 | struct add_volatile | |
1500 | { typedef _Tp volatile type; }; | |
1501 | ||
1502 | /// add_cv | |
1503 | template<typename _Tp> | |
1504 | struct add_cv | |
1505 | { | |
1506 | typedef typename | |
1507 | add_const<typename add_volatile<_Tp>::type>::type type; | |
1508 | }; | |
7b50cdef | 1509 | |
4457e88c | 1510 | #if __cplusplus > 201103L |
a15f7cb8 ESR |
1511 | |
1512 | #define __cpp_lib_transformation_trait_aliases 201304 | |
1513 | ||
4457e88c JW |
1514 | /// Alias template for remove_const |
1515 | template<typename _Tp> | |
1516 | using remove_const_t = typename remove_const<_Tp>::type; | |
1517 | ||
1518 | /// Alias template for remove_volatile | |
1519 | template<typename _Tp> | |
1520 | using remove_volatile_t = typename remove_volatile<_Tp>::type; | |
1521 | ||
1522 | /// Alias template for remove_cv | |
1523 | template<typename _Tp> | |
1524 | using remove_cv_t = typename remove_cv<_Tp>::type; | |
1525 | ||
1526 | /// Alias template for add_const | |
1527 | template<typename _Tp> | |
1528 | using add_const_t = typename add_const<_Tp>::type; | |
1529 | ||
1530 | /// Alias template for add_volatile | |
1531 | template<typename _Tp> | |
1532 | using add_volatile_t = typename add_volatile<_Tp>::type; | |
1533 | ||
1534 | /// Alias template for add_cv | |
1535 | template<typename _Tp> | |
1536 | using add_cv_t = typename add_cv<_Tp>::type; | |
1537 | #endif | |
7b50cdef | 1538 | |
123c516a | 1539 | // Reference transformations. |
7b50cdef | 1540 | |
123c516a PC |
1541 | /// remove_reference |
1542 | template<typename _Tp> | |
1543 | struct remove_reference | |
1544 | { typedef _Tp type; }; | |
7b50cdef | 1545 | |
123c516a PC |
1546 | template<typename _Tp> |
1547 | struct remove_reference<_Tp&> | |
1548 | { typedef _Tp type; }; | |
7b50cdef | 1549 | |
123c516a PC |
1550 | template<typename _Tp> |
1551 | struct remove_reference<_Tp&&> | |
1552 | { typedef _Tp type; }; | |
1553 | ||
89898034 | 1554 | template<typename _Tp, bool = __is_referenceable<_Tp>::value> |
123c516a PC |
1555 | struct __add_lvalue_reference_helper |
1556 | { typedef _Tp type; }; | |
7b50cdef | 1557 | |
5e108459 | 1558 | template<typename _Tp> |
89898034 | 1559 | struct __add_lvalue_reference_helper<_Tp, true> |
123c516a | 1560 | { typedef _Tp& type; }; |
5e108459 | 1561 | |
123c516a | 1562 | /// add_lvalue_reference |
5e108459 | 1563 | template<typename _Tp> |
123c516a PC |
1564 | struct add_lvalue_reference |
1565 | : public __add_lvalue_reference_helper<_Tp> | |
1566 | { }; | |
1567 | ||
89898034 | 1568 | template<typename _Tp, bool = __is_referenceable<_Tp>::value> |
123c516a PC |
1569 | struct __add_rvalue_reference_helper |
1570 | { typedef _Tp type; }; | |
5e108459 PC |
1571 | |
1572 | template<typename _Tp> | |
123c516a PC |
1573 | struct __add_rvalue_reference_helper<_Tp, true> |
1574 | { typedef _Tp&& type; }; | |
5e108459 | 1575 | |
123c516a | 1576 | /// add_rvalue_reference |
5e108459 | 1577 | template<typename _Tp> |
123c516a PC |
1578 | struct add_rvalue_reference |
1579 | : public __add_rvalue_reference_helper<_Tp> | |
1580 | { }; | |
5e108459 | 1581 | |
4457e88c JW |
1582 | #if __cplusplus > 201103L |
1583 | /// Alias template for remove_reference | |
1584 | template<typename _Tp> | |
1585 | using remove_reference_t = typename remove_reference<_Tp>::type; | |
1586 | ||
1587 | /// Alias template for add_lvalue_reference | |
1588 | template<typename _Tp> | |
1589 | using add_lvalue_reference_t = typename add_lvalue_reference<_Tp>::type; | |
1590 | ||
1591 | /// Alias template for add_rvalue_reference | |
1592 | template<typename _Tp> | |
1593 | using add_rvalue_reference_t = typename add_rvalue_reference<_Tp>::type; | |
1594 | #endif | |
7b50cdef | 1595 | |
c0ffa2ba | 1596 | // Sign modifications. |
123c516a | 1597 | |
7b50cdef BK |
1598 | // Utility for constructing identically cv-qualified types. |
1599 | template<typename _Unqualified, bool _IsConst, bool _IsVol> | |
1600 | struct __cv_selector; | |
1601 | ||
1602 | template<typename _Unqualified> | |
1603 | struct __cv_selector<_Unqualified, false, false> | |
1604 | { typedef _Unqualified __type; }; | |
1605 | ||
1606 | template<typename _Unqualified> | |
1607 | struct __cv_selector<_Unqualified, false, true> | |
1608 | { typedef volatile _Unqualified __type; }; | |
1609 | ||
1610 | template<typename _Unqualified> | |
1611 | struct __cv_selector<_Unqualified, true, false> | |
1612 | { typedef const _Unqualified __type; }; | |
1613 | ||
1614 | template<typename _Unqualified> | |
1615 | struct __cv_selector<_Unqualified, true, true> | |
1616 | { typedef const volatile _Unqualified __type; }; | |
1617 | ||
1618 | template<typename _Qualified, typename _Unqualified, | |
1619 | bool _IsConst = is_const<_Qualified>::value, | |
1620 | bool _IsVol = is_volatile<_Qualified>::value> | |
b0302c68 | 1621 | class __match_cv_qualifiers |
7b50cdef | 1622 | { |
7b50cdef BK |
1623 | typedef __cv_selector<_Unqualified, _IsConst, _IsVol> __match; |
1624 | ||
1625 | public: | |
1626 | typedef typename __match::__type __type; | |
1627 | }; | |
1628 | ||
7b50cdef BK |
1629 | // Utility for finding the unsigned versions of signed integral types. |
1630 | template<typename _Tp> | |
e133ace8 PC |
1631 | struct __make_unsigned |
1632 | { typedef _Tp __type; }; | |
7b50cdef BK |
1633 | |
1634 | template<> | |
1635 | struct __make_unsigned<char> | |
1636 | { typedef unsigned char __type; }; | |
1637 | ||
1638 | template<> | |
1639 | struct __make_unsigned<signed char> | |
1640 | { typedef unsigned char __type; }; | |
1641 | ||
7b50cdef BK |
1642 | template<> |
1643 | struct __make_unsigned<short> | |
1644 | { typedef unsigned short __type; }; | |
1645 | ||
1646 | template<> | |
1647 | struct __make_unsigned<int> | |
1648 | { typedef unsigned int __type; }; | |
1649 | ||
1650 | template<> | |
1651 | struct __make_unsigned<long> | |
1652 | { typedef unsigned long __type; }; | |
1653 | ||
1654 | template<> | |
1655 | struct __make_unsigned<long long> | |
1656 | { typedef unsigned long long __type; }; | |
1657 | ||
c0eef1c8 JW |
1658 | #if defined(_GLIBCXX_USE_WCHAR_T) && !defined(__WCHAR_UNSIGNED__) |
1659 | template<> | |
1660 | struct __make_unsigned<wchar_t> : __make_unsigned<__WCHAR_TYPE__> | |
1661 | { }; | |
1662 | #endif | |
1663 | ||
6d585f01 PC |
1664 | #if !defined(__STRICT_ANSI__) && defined(_GLIBCXX_USE_INT128) |
1665 | template<> | |
fd1e62c2 PC |
1666 | struct __make_unsigned<__int128> |
1667 | { typedef unsigned __int128 __type; }; | |
6d585f01 PC |
1668 | #endif |
1669 | ||
7b50cdef BK |
1670 | // Select between integral and enum: not possible to be both. |
1671 | template<typename _Tp, | |
1672 | bool _IsInt = is_integral<_Tp>::value, | |
7b50cdef | 1673 | bool _IsEnum = is_enum<_Tp>::value> |
b0302c68 PC |
1674 | class __make_unsigned_selector; |
1675 | ||
7b50cdef | 1676 | template<typename _Tp> |
b0302c68 | 1677 | class __make_unsigned_selector<_Tp, true, false> |
7b50cdef | 1678 | { |
7b50cdef BK |
1679 | typedef __make_unsigned<typename remove_cv<_Tp>::type> __unsignedt; |
1680 | typedef typename __unsignedt::__type __unsigned_type; | |
1681 | typedef __match_cv_qualifiers<_Tp, __unsigned_type> __cv_unsigned; | |
1682 | ||
1683 | public: | |
1684 | typedef typename __cv_unsigned::__type __type; | |
1685 | }; | |
1686 | ||
7b50cdef | 1687 | template<typename _Tp> |
b0302c68 | 1688 | class __make_unsigned_selector<_Tp, false, true> |
7b50cdef | 1689 | { |
a0230468 MM |
1690 | // With -fshort-enums, an enum may be as small as a char. |
1691 | typedef unsigned char __smallest; | |
1692 | static const bool __b0 = sizeof(_Tp) <= sizeof(__smallest); | |
1693 | static const bool __b1 = sizeof(_Tp) <= sizeof(unsigned short); | |
ce2e6349 | 1694 | static const bool __b2 = sizeof(_Tp) <= sizeof(unsigned int); |
a0230468 MM |
1695 | typedef conditional<__b2, unsigned int, unsigned long> __cond2; |
1696 | typedef typename __cond2::type __cond2_type; | |
1697 | typedef conditional<__b1, unsigned short, __cond2_type> __cond1; | |
1698 | typedef typename __cond1::type __cond1_type; | |
7b50cdef BK |
1699 | |
1700 | public: | |
a0230468 | 1701 | typedef typename conditional<__b0, __smallest, __cond1_type>::type __type; |
7b50cdef BK |
1702 | }; |
1703 | ||
7b50cdef BK |
1704 | // Given an integral/enum type, return the corresponding unsigned |
1705 | // integer type. | |
5b9daa7e BK |
1706 | // Primary template. |
1707 | /// make_unsigned | |
7b50cdef BK |
1708 | template<typename _Tp> |
1709 | struct make_unsigned | |
1710 | { typedef typename __make_unsigned_selector<_Tp>::__type type; }; | |
1711 | ||
1712 | // Integral, but don't define. | |
1713 | template<> | |
1714 | struct make_unsigned<bool>; | |
1715 | ||
1716 | ||
1717 | // Utility for finding the signed versions of unsigned integral types. | |
1718 | template<typename _Tp> | |
e133ace8 PC |
1719 | struct __make_signed |
1720 | { typedef _Tp __type; }; | |
7b50cdef BK |
1721 | |
1722 | template<> | |
1723 | struct __make_signed<char> | |
1724 | { typedef signed char __type; }; | |
1725 | ||
1726 | template<> | |
1727 | struct __make_signed<unsigned char> | |
1728 | { typedef signed char __type; }; | |
1729 | ||
7b50cdef BK |
1730 | template<> |
1731 | struct __make_signed<unsigned short> | |
1732 | { typedef signed short __type; }; | |
1733 | ||
1734 | template<> | |
1735 | struct __make_signed<unsigned int> | |
1736 | { typedef signed int __type; }; | |
1737 | ||
1738 | template<> | |
1739 | struct __make_signed<unsigned long> | |
1740 | { typedef signed long __type; }; | |
1741 | ||
1742 | template<> | |
1743 | struct __make_signed<unsigned long long> | |
1744 | { typedef signed long long __type; }; | |
1745 | ||
c0eef1c8 JW |
1746 | #if defined(_GLIBCXX_USE_WCHAR_T) && defined(__WCHAR_UNSIGNED__) |
1747 | template<> | |
1748 | struct __make_signed<wchar_t> : __make_signed<__WCHAR_TYPE__> | |
1749 | { }; | |
1750 | #endif | |
1751 | ||
1752 | #ifdef _GLIBCXX_USE_C99_STDINT_TR1 | |
1753 | template<> | |
1754 | struct __make_signed<char16_t> : __make_signed<uint_least16_t> | |
1755 | { }; | |
1756 | template<> | |
1757 | struct __make_signed<char32_t> : __make_signed<uint_least32_t> | |
1758 | { }; | |
1759 | #endif | |
1760 | ||
6d585f01 PC |
1761 | #if !defined(__STRICT_ANSI__) && defined(_GLIBCXX_USE_INT128) |
1762 | template<> | |
fd1e62c2 PC |
1763 | struct __make_signed<unsigned __int128> |
1764 | { typedef __int128 __type; }; | |
6d585f01 PC |
1765 | #endif |
1766 | ||
fb8ffd10 | 1767 | // Select between integral and enum: not possible to be both. |
7b50cdef BK |
1768 | template<typename _Tp, |
1769 | bool _IsInt = is_integral<_Tp>::value, | |
7b50cdef | 1770 | bool _IsEnum = is_enum<_Tp>::value> |
b0302c68 PC |
1771 | class __make_signed_selector; |
1772 | ||
7b50cdef | 1773 | template<typename _Tp> |
b0302c68 | 1774 | class __make_signed_selector<_Tp, true, false> |
7b50cdef | 1775 | { |
7b50cdef BK |
1776 | typedef __make_signed<typename remove_cv<_Tp>::type> __signedt; |
1777 | typedef typename __signedt::__type __signed_type; | |
1778 | typedef __match_cv_qualifiers<_Tp, __signed_type> __cv_signed; | |
1779 | ||
1780 | public: | |
1781 | typedef typename __cv_signed::__type __type; | |
1782 | }; | |
1783 | ||
7b50cdef | 1784 | template<typename _Tp> |
b0302c68 | 1785 | class __make_signed_selector<_Tp, false, true> |
7b50cdef | 1786 | { |
a0230468 MM |
1787 | // With -fshort-enums, an enum may be as small as a char. |
1788 | typedef signed char __smallest; | |
1789 | static const bool __b0 = sizeof(_Tp) <= sizeof(__smallest); | |
1790 | static const bool __b1 = sizeof(_Tp) <= sizeof(signed short); | |
ce2e6349 | 1791 | static const bool __b2 = sizeof(_Tp) <= sizeof(signed int); |
a0230468 MM |
1792 | typedef conditional<__b2, signed int, signed long> __cond2; |
1793 | typedef typename __cond2::type __cond2_type; | |
1794 | typedef conditional<__b1, signed short, __cond2_type> __cond1; | |
1795 | typedef typename __cond1::type __cond1_type; | |
7b50cdef BK |
1796 | |
1797 | public: | |
a0230468 | 1798 | typedef typename conditional<__b0, __smallest, __cond1_type>::type __type; |
7b50cdef BK |
1799 | }; |
1800 | ||
7b50cdef BK |
1801 | // Given an integral/enum type, return the corresponding signed |
1802 | // integer type. | |
5b9daa7e BK |
1803 | // Primary template. |
1804 | /// make_signed | |
7b50cdef BK |
1805 | template<typename _Tp> |
1806 | struct make_signed | |
1807 | { typedef typename __make_signed_selector<_Tp>::__type type; }; | |
1808 | ||
1809 | // Integral, but don't define. | |
1810 | template<> | |
1811 | struct make_signed<bool>; | |
cfa9a96b | 1812 | |
4457e88c JW |
1813 | #if __cplusplus > 201103L |
1814 | /// Alias template for make_signed | |
1815 | template<typename _Tp> | |
1816 | using make_signed_t = typename make_signed<_Tp>::type; | |
1817 | ||
1818 | /// Alias template for make_unsigned | |
1819 | template<typename _Tp> | |
1820 | using make_unsigned_t = typename make_unsigned<_Tp>::type; | |
1821 | #endif | |
123c516a | 1822 | |
c0ffa2ba | 1823 | // Array modifications. |
123c516a PC |
1824 | |
1825 | /// remove_extent | |
1826 | template<typename _Tp> | |
1827 | struct remove_extent | |
1828 | { typedef _Tp type; }; | |
1829 | ||
1830 | template<typename _Tp, std::size_t _Size> | |
1831 | struct remove_extent<_Tp[_Size]> | |
1832 | { typedef _Tp type; }; | |
1833 | ||
1834 | template<typename _Tp> | |
1835 | struct remove_extent<_Tp[]> | |
1836 | { typedef _Tp type; }; | |
1837 | ||
1838 | /// remove_all_extents | |
1839 | template<typename _Tp> | |
1840 | struct remove_all_extents | |
1841 | { typedef _Tp type; }; | |
1842 | ||
1843 | template<typename _Tp, std::size_t _Size> | |
1844 | struct remove_all_extents<_Tp[_Size]> | |
1845 | { typedef typename remove_all_extents<_Tp>::type type; }; | |
1846 | ||
1847 | template<typename _Tp> | |
1848 | struct remove_all_extents<_Tp[]> | |
1849 | { typedef typename remove_all_extents<_Tp>::type type; }; | |
1850 | ||
4457e88c JW |
1851 | #if __cplusplus > 201103L |
1852 | /// Alias template for remove_extent | |
1853 | template<typename _Tp> | |
1854 | using remove_extent_t = typename remove_extent<_Tp>::type; | |
1855 | ||
1856 | /// Alias template for remove_all_extents | |
1857 | template<typename _Tp> | |
1858 | using remove_all_extents_t = typename remove_all_extents<_Tp>::type; | |
1859 | #endif | |
123c516a | 1860 | |
c0ffa2ba | 1861 | // Pointer modifications. |
123c516a PC |
1862 | |
1863 | template<typename _Tp, typename> | |
1864 | struct __remove_pointer_helper | |
1865 | { typedef _Tp type; }; | |
1866 | ||
1867 | template<typename _Tp, typename _Up> | |
1868 | struct __remove_pointer_helper<_Tp, _Up*> | |
1869 | { typedef _Up type; }; | |
1870 | ||
1871 | /// remove_pointer | |
1872 | template<typename _Tp> | |
1873 | struct remove_pointer | |
1874 | : public __remove_pointer_helper<_Tp, typename remove_cv<_Tp>::type> | |
1875 | { }; | |
1876 | ||
1877 | /// add_pointer | |
89898034 DK |
1878 | template<typename _Tp, bool = __or_<__is_referenceable<_Tp>, |
1879 | is_void<_Tp>>::value> | |
1880 | struct __add_pointer_helper | |
1881 | { typedef _Tp type; }; | |
1882 | ||
123c516a | 1883 | template<typename _Tp> |
89898034 | 1884 | struct __add_pointer_helper<_Tp, true> |
123c516a PC |
1885 | { typedef typename remove_reference<_Tp>::type* type; }; |
1886 | ||
89898034 DK |
1887 | template<typename _Tp> |
1888 | struct add_pointer | |
1889 | : public __add_pointer_helper<_Tp> | |
1890 | { }; | |
1891 | ||
4457e88c JW |
1892 | #if __cplusplus > 201103L |
1893 | /// Alias template for remove_pointer | |
1894 | template<typename _Tp> | |
1895 | using remove_pointer_t = typename remove_pointer<_Tp>::type; | |
1896 | ||
1897 | /// Alias template for add_pointer | |
1898 | template<typename _Tp> | |
1899 | using add_pointer_t = typename add_pointer<_Tp>::type; | |
1900 | #endif | |
123c516a PC |
1901 | |
1902 | template<std::size_t _Len> | |
1903 | struct __aligned_storage_msa | |
1904 | { | |
1905 | union __type | |
1906 | { | |
1907 | unsigned char __data[_Len]; | |
1908 | struct __attribute__((__aligned__)) { } __align; | |
1909 | }; | |
1910 | }; | |
1911 | ||
1912 | /** | |
1913 | * @brief Alignment type. | |
1914 | * | |
1915 | * The value of _Align is a default-alignment which shall be the | |
1916 | * most stringent alignment requirement for any C++ object type | |
1917 | * whose size is no greater than _Len (3.9). The member typedef | |
1918 | * type shall be a POD type suitable for use as uninitialized | |
1919 | * storage for any object whose size is at most _Len and whose | |
1920 | * alignment is a divisor of _Align. | |
1921 | */ | |
1922 | template<std::size_t _Len, std::size_t _Align = | |
1923 | __alignof__(typename __aligned_storage_msa<_Len>::__type)> | |
1924 | struct aligned_storage | |
1925 | { | |
1926 | union type | |
1927 | { | |
1928 | unsigned char __data[_Len]; | |
1929 | struct __attribute__((__aligned__((_Align)))) { } __align; | |
1930 | }; | |
1931 | }; | |
1932 | ||
d3718027 RS |
1933 | template <typename... _Types> |
1934 | struct __strictest_alignment | |
1935 | { | |
1936 | static const size_t _S_alignment = 0; | |
1937 | static const size_t _S_size = 0; | |
1938 | }; | |
1939 | ||
1940 | template <typename _Tp, typename... _Types> | |
1941 | struct __strictest_alignment<_Tp, _Types...> | |
1942 | { | |
1943 | static const size_t _S_alignment = | |
1944 | alignof(_Tp) > __strictest_alignment<_Types...>::_S_alignment | |
1945 | ? alignof(_Tp) : __strictest_alignment<_Types...>::_S_alignment; | |
1946 | static const size_t _S_size = | |
1947 | sizeof(_Tp) > __strictest_alignment<_Types...>::_S_size | |
1948 | ? sizeof(_Tp) : __strictest_alignment<_Types...>::_S_size; | |
1949 | }; | |
1950 | ||
1951 | /** | |
1952 | * @brief Provide aligned storage for types. | |
1953 | * | |
1954 | * [meta.trans.other] | |
1955 | * | |
1956 | * Provides aligned storage for any of the provided types of at | |
1957 | * least size _Len. | |
1958 | * | |
1959 | * @see aligned_storage | |
1960 | */ | |
1961 | template <size_t _Len, typename... _Types> | |
1962 | struct aligned_union | |
1963 | { | |
1964 | private: | |
1965 | static_assert(sizeof...(_Types) != 0, "At least one type is required"); | |
1966 | ||
1967 | using __strictest = __strictest_alignment<_Types...>; | |
1968 | static const size_t _S_len = _Len > __strictest::_S_size | |
1969 | ? _Len : __strictest::_S_size; | |
1970 | public: | |
1971 | /// The value of the strictest alignment of _Types. | |
1972 | static const size_t alignment_value = __strictest::_S_alignment; | |
1973 | /// The storage. | |
1974 | typedef typename aligned_storage<_S_len, alignment_value>::type type; | |
1975 | }; | |
1976 | ||
1977 | template <size_t _Len, typename... _Types> | |
1978 | const size_t aligned_union<_Len, _Types...>::alignment_value; | |
123c516a PC |
1979 | |
1980 | // Decay trait for arrays and functions, used for perfect forwarding | |
1981 | // in make_pair, make_tuple, etc. | |
1982 | template<typename _Up, | |
1983 | bool _IsArray = is_array<_Up>::value, | |
1984 | bool _IsFunction = is_function<_Up>::value> | |
1985 | struct __decay_selector; | |
1986 | ||
1987 | // NB: DR 705. | |
1988 | template<typename _Up> | |
1989 | struct __decay_selector<_Up, false, false> | |
1990 | { typedef typename remove_cv<_Up>::type __type; }; | |
1991 | ||
1992 | template<typename _Up> | |
1993 | struct __decay_selector<_Up, true, false> | |
1994 | { typedef typename remove_extent<_Up>::type* __type; }; | |
1995 | ||
1996 | template<typename _Up> | |
1997 | struct __decay_selector<_Up, false, true> | |
1998 | { typedef typename add_pointer<_Up>::type __type; }; | |
1999 | ||
2000 | /// decay | |
2001 | template<typename _Tp> | |
2002 | class decay | |
2003 | { | |
2004 | typedef typename remove_reference<_Tp>::type __remove_type; | |
2005 | ||
2006 | public: | |
2007 | typedef typename __decay_selector<__remove_type>::__type type; | |
2008 | }; | |
2009 | ||
2010 | template<typename _Tp> | |
2011 | class reference_wrapper; | |
2012 | ||
2013 | // Helper which adds a reference to a type when given a reference_wrapper | |
2014 | template<typename _Tp> | |
2015 | struct __strip_reference_wrapper | |
2016 | { | |
2017 | typedef _Tp __type; | |
2018 | }; | |
2019 | ||
2020 | template<typename _Tp> | |
2021 | struct __strip_reference_wrapper<reference_wrapper<_Tp> > | |
2022 | { | |
2023 | typedef _Tp& __type; | |
2024 | }; | |
2025 | ||
123c516a PC |
2026 | template<typename _Tp> |
2027 | struct __decay_and_strip | |
2028 | { | |
2029 | typedef typename __strip_reference_wrapper< | |
2030 | typename decay<_Tp>::type>::__type __type; | |
2031 | }; | |
2032 | ||
2033 | ||
123c516a | 2034 | // Primary template. |
13901e4b | 2035 | /// Define a member typedef @c type only if a boolean constant is true. |
123c516a PC |
2036 | template<bool, typename _Tp = void> |
2037 | struct enable_if | |
2038 | { }; | |
2039 | ||
2040 | // Partial specialization for true. | |
2041 | template<typename _Tp> | |
2042 | struct enable_if<true, _Tp> | |
2043 | { typedef _Tp type; }; | |
2044 | ||
23df8534 JW |
2045 | template<typename... _Cond> |
2046 | using _Require = typename enable_if<__and_<_Cond...>::value>::type; | |
123c516a | 2047 | |
123c516a | 2048 | // Primary template. |
13901e4b | 2049 | /// Define a member typedef @c type to one of two argument types. |
123c516a PC |
2050 | template<bool _Cond, typename _Iftrue, typename _Iffalse> |
2051 | struct conditional | |
2052 | { typedef _Iftrue type; }; | |
2053 | ||
2054 | // Partial specialization for false. | |
2055 | template<typename _Iftrue, typename _Iffalse> | |
2056 | struct conditional<false, _Iftrue, _Iffalse> | |
2057 | { typedef _Iffalse type; }; | |
2058 | ||
5b9daa7e | 2059 | /// common_type |
cfa9a96b CF |
2060 | template<typename... _Tp> |
2061 | struct common_type; | |
2062 | ||
c0ffa2ba | 2063 | // Sfinae-friendly common_type implementation: |
b3618b71 DK |
2064 | |
2065 | struct __do_common_type_impl | |
2066 | { | |
2067 | template<typename _Tp, typename _Up> | |
6c5173c0 | 2068 | static __success_type<typename decay<decltype |
fe4e4e3b | 2069 | (true ? std::declval<_Tp>() |
6c5173c0 | 2070 | : std::declval<_Up>())>::type> _S_test(int); |
b3618b71 DK |
2071 | |
2072 | template<typename, typename> | |
2073 | static __failure_type _S_test(...); | |
2074 | }; | |
2075 | ||
2076 | template<typename _Tp, typename _Up> | |
2077 | struct __common_type_impl | |
2078 | : private __do_common_type_impl | |
2079 | { | |
2080 | typedef decltype(_S_test<_Tp, _Up>(0)) type; | |
2081 | }; | |
2082 | ||
2083 | struct __do_member_type_wrapper | |
2084 | { | |
2085 | template<typename _Tp> | |
2086 | static __success_type<typename _Tp::type> _S_test(int); | |
2087 | ||
2088 | template<typename> | |
2089 | static __failure_type _S_test(...); | |
2090 | }; | |
2091 | ||
2092 | template<typename _Tp> | |
2093 | struct __member_type_wrapper | |
2094 | : private __do_member_type_wrapper | |
2095 | { | |
2096 | typedef decltype(_S_test<_Tp>(0)) type; | |
2097 | }; | |
2098 | ||
2099 | template<typename _CTp, typename... _Args> | |
2100 | struct __expanded_common_type_wrapper | |
2101 | { | |
2102 | typedef common_type<typename _CTp::type, _Args...> type; | |
2103 | }; | |
2104 | ||
2105 | template<typename... _Args> | |
2106 | struct __expanded_common_type_wrapper<__failure_type, _Args...> | |
2107 | { typedef __failure_type type; }; | |
2108 | ||
cfa9a96b CF |
2109 | template<typename _Tp> |
2110 | struct common_type<_Tp> | |
6c5173c0 | 2111 | { typedef typename decay<_Tp>::type type; }; |
cfa9a96b CF |
2112 | |
2113 | template<typename _Tp, typename _Up> | |
7274deff | 2114 | struct common_type<_Tp, _Up> |
b3618b71 DK |
2115 | : public __common_type_impl<_Tp, _Up>::type |
2116 | { }; | |
cfa9a96b CF |
2117 | |
2118 | template<typename _Tp, typename _Up, typename... _Vp> | |
2119 | struct common_type<_Tp, _Up, _Vp...> | |
b3618b71 DK |
2120 | : public __expanded_common_type_wrapper<typename __member_type_wrapper< |
2121 | common_type<_Tp, _Up>>::type, _Vp...>::type | |
2122 | { }; | |
7274deff | 2123 | |
13901e4b | 2124 | /// The underlying type of an enum. |
a47407f6 PC |
2125 | template<typename _Tp> |
2126 | struct underlying_type | |
2127 | { | |
2128 | typedef __underlying_type(_Tp) type; | |
2129 | }; | |
123c516a | 2130 | |
7274deff PC |
2131 | template<typename _Tp> |
2132 | struct __declval_protector | |
2133 | { | |
2134 | static const bool __stop = false; | |
2135 | static typename add_rvalue_reference<_Tp>::type __delegate(); | |
2136 | }; | |
2137 | ||
2138 | template<typename _Tp> | |
2139 | inline typename add_rvalue_reference<_Tp>::type | |
e4f32cb0 | 2140 | declval() noexcept |
7274deff PC |
2141 | { |
2142 | static_assert(__declval_protector<_Tp>::__stop, | |
2143 | "declval() must not be used!"); | |
2144 | return __declval_protector<_Tp>::__delegate(); | |
2145 | } | |
1041daba | 2146 | |
be7f7822 JW |
2147 | /// result_of |
2148 | template<typename _Signature> | |
2149 | class result_of; | |
2150 | ||
c0ffa2ba | 2151 | // Sfinae-friendly result_of implementation: |
83ddb39f | 2152 | |
a15f7cb8 ESR |
2153 | #define __cpp_lib_result_of_sfinae 201210 |
2154 | ||
83ddb39f DK |
2155 | // [func.require] paragraph 1 bullet 1: |
2156 | struct __result_of_memfun_ref_impl | |
2157 | { | |
2158 | template<typename _Fp, typename _Tp1, typename... _Args> | |
2159 | static __success_type<decltype( | |
2160 | (std::declval<_Tp1>().*std::declval<_Fp>())(std::declval<_Args>()...) | |
2161 | )> _S_test(int); | |
2162 | ||
2163 | template<typename...> | |
2164 | static __failure_type _S_test(...); | |
2165 | }; | |
2166 | ||
2167 | template<typename _MemPtr, typename _Arg, typename... _Args> | |
2168 | struct __result_of_memfun_ref | |
2169 | : private __result_of_memfun_ref_impl | |
2170 | { | |
2171 | typedef decltype(_S_test<_MemPtr, _Arg, _Args...>(0)) type; | |
2172 | }; | |
2173 | ||
2174 | // [func.require] paragraph 1 bullet 2: | |
2175 | struct __result_of_memfun_deref_impl | |
2176 | { | |
2177 | template<typename _Fp, typename _Tp1, typename... _Args> | |
2178 | static __success_type<decltype( | |
2179 | ((*std::declval<_Tp1>()).*std::declval<_Fp>())(std::declval<_Args>()...) | |
2180 | )> _S_test(int); | |
2181 | ||
2182 | template<typename...> | |
2183 | static __failure_type _S_test(...); | |
2184 | }; | |
2185 | ||
2186 | template<typename _MemPtr, typename _Arg, typename... _Args> | |
2187 | struct __result_of_memfun_deref | |
2188 | : private __result_of_memfun_deref_impl | |
2189 | { | |
2190 | typedef decltype(_S_test<_MemPtr, _Arg, _Args...>(0)) type; | |
2191 | }; | |
2192 | ||
2193 | // [func.require] paragraph 1 bullet 3: | |
2194 | struct __result_of_memobj_ref_impl | |
2195 | { | |
2196 | template<typename _Fp, typename _Tp1> | |
2197 | static __success_type<decltype( | |
2198 | std::declval<_Tp1>().*std::declval<_Fp>() | |
2199 | )> _S_test(int); | |
2200 | ||
2201 | template<typename, typename> | |
2202 | static __failure_type _S_test(...); | |
2203 | }; | |
2204 | ||
2205 | template<typename _MemPtr, typename _Arg> | |
2206 | struct __result_of_memobj_ref | |
2207 | : private __result_of_memobj_ref_impl | |
2208 | { | |
2209 | typedef decltype(_S_test<_MemPtr, _Arg>(0)) type; | |
2210 | }; | |
2211 | ||
2212 | // [func.require] paragraph 1 bullet 4: | |
2213 | struct __result_of_memobj_deref_impl | |
2214 | { | |
2215 | template<typename _Fp, typename _Tp1> | |
2216 | static __success_type<decltype( | |
2217 | (*std::declval<_Tp1>()).*std::declval<_Fp>() | |
2218 | )> _S_test(int); | |
2219 | ||
2220 | template<typename, typename> | |
2221 | static __failure_type _S_test(...); | |
2222 | }; | |
2223 | ||
be7f7822 | 2224 | template<typename _MemPtr, typename _Arg> |
83ddb39f DK |
2225 | struct __result_of_memobj_deref |
2226 | : private __result_of_memobj_deref_impl | |
2227 | { | |
2228 | typedef decltype(_S_test<_MemPtr, _Arg>(0)) type; | |
2229 | }; | |
2230 | ||
2231 | template<typename _MemPtr, typename _Arg> | |
2232 | struct __result_of_memobj; | |
be7f7822 JW |
2233 | |
2234 | template<typename _Res, typename _Class, typename _Arg> | |
83ddb39f | 2235 | struct __result_of_memobj<_Res _Class::*, _Arg> |
be7f7822 | 2236 | { |
83ddb39f DK |
2237 | typedef typename remove_cv<typename remove_reference< |
2238 | _Arg>::type>::type _Argval; | |
2239 | typedef _Res _Class::* _MemPtr; | |
2240 | typedef typename conditional<__or_<is_same<_Argval, _Class>, | |
2241 | is_base_of<_Class, _Argval>>::value, | |
2242 | __result_of_memobj_ref<_MemPtr, _Arg>, | |
2243 | __result_of_memobj_deref<_MemPtr, _Arg> | |
2244 | >::type::type type; | |
be7f7822 JW |
2245 | }; |
2246 | ||
83ddb39f DK |
2247 | template<typename _MemPtr, typename _Arg, typename... _Args> |
2248 | struct __result_of_memfun; | |
be7f7822 JW |
2249 | |
2250 | template<typename _Res, typename _Class, typename _Arg, typename... _Args> | |
83ddb39f | 2251 | struct __result_of_memfun<_Res _Class::*, _Arg, _Args...> |
be7f7822 | 2252 | { |
83ddb39f DK |
2253 | typedef typename remove_cv<typename remove_reference< |
2254 | _Arg>::type>::type _Argval; | |
2255 | typedef _Res _Class::* _MemPtr; | |
2256 | typedef typename conditional<__or_<is_same<_Argval, _Class>, | |
2257 | is_base_of<_Class, _Argval>>::value, | |
2258 | __result_of_memfun_ref<_MemPtr, _Arg, _Args...>, | |
2259 | __result_of_memfun_deref<_MemPtr, _Arg, _Args...> | |
2260 | >::type::type type; | |
be7f7822 JW |
2261 | }; |
2262 | ||
2263 | template<bool, bool, typename _Functor, typename... _ArgTypes> | |
83ddb39f | 2264 | struct __result_of_impl |
be7f7822 | 2265 | { |
83ddb39f | 2266 | typedef __failure_type type; |
be7f7822 JW |
2267 | }; |
2268 | ||
2269 | template<typename _MemPtr, typename _Arg> | |
83ddb39f DK |
2270 | struct __result_of_impl<true, false, _MemPtr, _Arg> |
2271 | : public __result_of_memobj<typename decay<_MemPtr>::type, _Arg> | |
c4db9a77 | 2272 | { }; |
be7f7822 | 2273 | |
83ddb39f DK |
2274 | template<typename _MemPtr, typename _Arg, typename... _Args> |
2275 | struct __result_of_impl<false, true, _MemPtr, _Arg, _Args...> | |
2276 | : public __result_of_memfun<typename decay<_MemPtr>::type, _Arg, _Args...> | |
c4db9a77 | 2277 | { }; |
be7f7822 | 2278 | |
83ddb39f DK |
2279 | // [func.require] paragraph 1 bullet 5: |
2280 | struct __result_of_other_impl | |
2281 | { | |
2282 | template<typename _Fn, typename... _Args> | |
2283 | static __success_type<decltype( | |
2284 | std::declval<_Fn>()(std::declval<_Args>()...) | |
2285 | )> _S_test(int); | |
2286 | ||
2287 | template<typename...> | |
2288 | static __failure_type _S_test(...); | |
2289 | }; | |
2290 | ||
be7f7822 | 2291 | template<typename _Functor, typename... _ArgTypes> |
83ddb39f DK |
2292 | struct __result_of_impl<false, false, _Functor, _ArgTypes...> |
2293 | : private __result_of_other_impl | |
be7f7822 | 2294 | { |
83ddb39f | 2295 | typedef decltype(_S_test<_Functor, _ArgTypes...>(0)) type; |
be7f7822 JW |
2296 | }; |
2297 | ||
83ddb39f DK |
2298 | template<typename _Functor, typename... _ArgTypes> |
2299 | struct result_of<_Functor(_ArgTypes...)> | |
2300 | : public __result_of_impl< | |
2301 | is_member_object_pointer< | |
2302 | typename remove_reference<_Functor>::type | |
2303 | >::value, | |
2304 | is_member_function_pointer< | |
2305 | typename remove_reference<_Functor>::type | |
2306 | >::value, | |
2307 | _Functor, _ArgTypes... | |
2308 | >::type | |
2309 | { }; | |
c0ffa2ba | 2310 | |
4457e88c JW |
2311 | #if __cplusplus > 201103L |
2312 | /// Alias template for aligned_storage | |
2313 | template<size_t _Len, size_t _Align = | |
2314 | __alignof__(typename __aligned_storage_msa<_Len>::__type)> | |
2315 | using aligned_storage_t = typename aligned_storage<_Len, _Align>::type; | |
2316 | ||
d3718027 RS |
2317 | template <size_t _Len, typename... _Types> |
2318 | using aligned_union_t = typename aligned_union<_Len, _Types...>::type; | |
2319 | ||
4457e88c JW |
2320 | /// Alias template for decay |
2321 | template<typename _Tp> | |
2322 | using decay_t = typename decay<_Tp>::type; | |
2323 | ||
2324 | /// Alias template for enable_if | |
2325 | template<bool _Cond, typename _Tp = void> | |
2326 | using enable_if_t = typename enable_if<_Cond, _Tp>::type; | |
2327 | ||
2328 | /// Alias template for conditional | |
2329 | template<bool _Cond, typename _Iftrue, typename _Iffalse> | |
2330 | using conditional_t = typename conditional<_Cond, _Iftrue, _Iffalse>::type; | |
2331 | ||
2332 | /// Alias template for common_type | |
2333 | template<typename... _Tp> | |
2334 | using common_type_t = typename common_type<_Tp...>::type; | |
2335 | ||
2336 | /// Alias template for underlying_type | |
2337 | template<typename _Tp> | |
2338 | using underlying_type_t = typename underlying_type<_Tp>::type; | |
2339 | ||
2340 | /// Alias template for result_of | |
2341 | template<typename _Tp> | |
2342 | using result_of_t = typename result_of<_Tp>::type; | |
2343 | #endif | |
2344 | ||
c0ffa2ba | 2345 | /// @} group metaprogramming |
83ddb39f | 2346 | |
033b71ce PC |
2347 | /** |
2348 | * Use SFINAE to determine if the type _Tp has a publicly-accessible | |
2349 | * member type _NTYPE. | |
2350 | */ | |
82b12c4b FD |
2351 | #define _GLIBCXX_HAS_NESTED_TYPE(_NTYPE) \ |
2352 | template<typename _Tp> \ | |
2353 | class __has_##_NTYPE##_helper \ | |
2354 | { \ | |
2355 | template<typename _Up> \ | |
2356 | struct _Wrap_type \ | |
2357 | { }; \ | |
2358 | \ | |
2359 | template<typename _Up> \ | |
2360 | static true_type __test(_Wrap_type<typename _Up::_NTYPE>*); \ | |
2361 | \ | |
2362 | template<typename _Up> \ | |
2363 | static false_type __test(...); \ | |
2364 | \ | |
2365 | public: \ | |
2366 | typedef decltype(__test<_Tp>(0)) type; \ | |
2367 | }; \ | |
2368 | \ | |
2369 | template<typename _Tp> \ | |
2370 | struct __has_##_NTYPE \ | |
2371 | : public __has_##_NTYPE##_helper \ | |
2372 | <typename remove_cv<_Tp>::type>::type \ | |
033b71ce PC |
2373 | { }; |
2374 | ||
12ffa228 | 2375 | _GLIBCXX_END_NAMESPACE_VERSION |
c0ffa2ba | 2376 | } // namespace std |
7b50cdef | 2377 | |
734f5023 | 2378 | #endif // C++11 |
57317d2a | 2379 | |
7274deff | 2380 | #endif // _GLIBCXX_TYPE_TRAITS |