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