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