Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

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