From Jason Turner

[meta]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpn27ez3zh/{from.md → to.md} +453 -227
tmp/tmpn27ez3zh/{from.md → to.md} RENAMED
@@ -1,53 +1,67 @@
1
  ## Metaprogramming and type traits <a id="meta">[[meta]]</a>
2
 
3
- This subclause describes components used by C++programs, particularly in
4
- templates, to support the widest possible range of types, optimise
5
  template code usage, detect type related user errors, and perform type
6
  inference and transformation at compile time. It includes type
7
  classification traits, type property inspection traits, and type
8
  transformations. The type classification traits describe a complete
9
  taxonomy of all possible C++ types, and state where in that taxonomy a
10
  given type belongs. The type property inspection traits allow important
11
  characteristics of types or of combinations of types to be inspected.
12
  The type transformations allow certain properties of types to be
13
  manipulated.
14
 
15
- All functions specified in this subclause are signal-safe (
16
- [[csignal.syn]]).
17
 
18
  ### Requirements <a id="meta.rqmts">[[meta.rqmts]]</a>
19
 
20
- A *UnaryTypeTrait* describes a property of a type. It shall be a class
21
- template that takes one template type argument and, optionally,
22
- additional arguments that help define the property being described. It
23
- shall be `DefaultConstructible`, `CopyConstructible`, and publicly and
24
  unambiguously derived, directly or indirectly, from its *base
25
  characteristic*, which is a specialization of the template
26
- `integral_constant` ([[meta.help]]), with the arguments to the template
27
  `integral_constant` determined by the requirements for the particular
28
  property being described. The member names of the base characteristic
29
  shall not be hidden and shall be unambiguously available in the
30
- `UnaryTypeTrait`.
31
 
32
- A *BinaryTypeTrait* describes a relationship between two types. It shall
33
- be a class template that takes two template type arguments and,
34
- optionally, additional arguments that help define the relationship being
35
- described. It shall be `DefaultConstructible`, `CopyConstructible`, and
36
  publicly and unambiguously derived, directly or indirectly, from its
37
  *base characteristic*, which is a specialization of the template
38
- `integral_constant` ([[meta.help]]), with the arguments to the template
39
  `integral_constant` determined by the requirements for the particular
40
  relationship being described. The member names of the base
41
  characteristic shall not be hidden and shall be unambiguously available
42
- in the `BinaryTypeTrait`.
43
 
44
- A *TransformationTrait* modifies a property of a type. It shall be a
45
- class template that takes one template type argument and, optionally,
46
- additional arguments that help define the modification. It shall define
47
- a publicly accessible nested type named `type`, which shall be a synonym
48
- for the modified type.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
 
50
  ### Header `<type_traits>` synopsis <a id="meta.type.synop">[[meta.type.synop]]</a>
51
 
52
  ``` cpp
53
  namespace std {
@@ -88,19 +102,20 @@ namespace std {
88
  template<class T> struct is_const;
89
  template<class T> struct is_volatile;
90
  template<class T> struct is_trivial;
91
  template<class T> struct is_trivially_copyable;
92
  template<class T> struct is_standard_layout;
93
- template <class T> struct is_pod;
94
  template<class T> struct is_empty;
95
  template<class T> struct is_polymorphic;
96
  template<class T> struct is_abstract;
97
  template<class T> struct is_final;
98
  template<class T> struct is_aggregate;
99
 
100
  template<class T> struct is_signed;
101
  template<class T> struct is_unsigned;
 
 
102
 
103
  template<class T, class... Args> struct is_constructible;
104
  template<class T> struct is_default_constructible;
105
  template<class T> struct is_copy_constructible;
106
  template<class T> struct is_move_constructible;
@@ -149,10 +164,13 @@ namespace std {
149
 
150
  // [meta.rel], type relations
151
  template<class T, class U> struct is_same;
152
  template<class Base, class Derived> struct is_base_of;
153
  template<class From, class To> struct is_convertible;
 
 
 
154
 
155
  template<class Fn, class... ArgTypes> struct is_invocable;
156
  template<class R, class Fn, class... ArgTypes> struct is_invocable_r;
157
 
158
  template<class Fn, class... ArgTypes> struct is_nothrow_invocable;
@@ -217,227 +235,269 @@ namespace std {
217
  using remove_pointer_t = typename remove_pointer<T>::type;
218
  template<class T>
219
  using add_pointer_t = typename add_pointer<T>::type;
220
 
221
  // [meta.trans.other], other transformations
222
- template <size_t Len,
223
- size_t Align = default-alignment> // see [meta.trans.other]
224
  struct aligned_storage;
225
  template<size_t Len, class... Types> struct aligned_union;
 
226
  template<class T> struct decay;
227
  template<bool, class T = void> struct enable_if;
228
  template<bool, class T, class F> struct conditional;
229
  template<class... T> struct common_type;
 
 
 
230
  template<class T> struct underlying_type;
231
  template<class Fn, class... ArgTypes> struct invoke_result;
 
 
232
 
233
- template <size_t Len,
234
- size_t Align = default-alignment> // see [meta.trans.other]
 
235
  using aligned_storage_t = typename aligned_storage<Len, Align>::type;
236
  template<size_t Len, class... Types>
237
  using aligned_union_t = typename aligned_union<Len, Types...>::type;
 
 
238
  template<class T>
239
  using decay_t = typename decay<T>::type;
240
  template<bool b, class T = void>
241
  using enable_if_t = typename enable_if<b, T>::type;
242
  template<bool b, class T, class F>
243
  using conditional_t = typename conditional<b, T, F>::type;
244
  template<class... T>
245
  using common_type_t = typename common_type<T...>::type;
 
 
246
  template<class T>
247
  using underlying_type_t = typename underlying_type<T>::type;
248
  template<class Fn, class... ArgTypes>
249
  using invoke_result_t = typename invoke_result<Fn, ArgTypes...>::type;
 
 
 
 
250
  template<class...>
251
  using void_t = void;
252
 
253
  // [meta.logical], logical operator traits
254
  template<class... B> struct conjunction;
255
  template<class... B> struct disjunction;
256
  template<class B> struct negation;
257
 
258
  // [meta.unary.cat], primary type categories
259
- template <class T> inline constexpr bool is_void_v
260
- = is_void<T>::value;
261
- template <class T> inline constexpr bool is_null_pointer_v
262
- = is_null_pointer<T>::value;
263
- template <class T> inline constexpr bool is_integral_v
264
- = is_integral<T>::value;
265
- template <class T> inline constexpr bool is_floating_point_v
266
- = is_floating_point<T>::value;
267
- template <class T> inline constexpr bool is_array_v
268
- = is_array<T>::value;
269
- template <class T> inline constexpr bool is_pointer_v
270
- = is_pointer<T>::value;
271
- template <class T> inline constexpr bool is_lvalue_reference_v
272
- = is_lvalue_reference<T>::value;
273
- template <class T> inline constexpr bool is_rvalue_reference_v
274
- = is_rvalue_reference<T>::value;
275
- template <class T> inline constexpr bool is_member_object_pointer_v
276
- = is_member_object_pointer<T>::value;
277
- template <class T> inline constexpr bool is_member_function_pointer_v
278
- = is_member_function_pointer<T>::value;
279
- template <class T> inline constexpr bool is_enum_v
280
- = is_enum<T>::value;
281
- template <class T> inline constexpr bool is_union_v
282
- = is_union<T>::value;
283
- template <class T> inline constexpr bool is_class_v
284
- = is_class<T>::value;
285
- template <class T> inline constexpr bool is_function_v
286
- = is_function<T>::value;
287
 
288
  // [meta.unary.comp], composite type categories
289
- template <class T> inline constexpr bool is_reference_v
290
- = is_reference<T>::value;
291
- template <class T> inline constexpr bool is_arithmetic_v
292
- = is_arithmetic<T>::value;
293
- template <class T> inline constexpr bool is_fundamental_v
294
- = is_fundamental<T>::value;
295
- template <class T> inline constexpr bool is_object_v
296
- = is_object<T>::value;
297
- template <class T> inline constexpr bool is_scalar_v
298
- = is_scalar<T>::value;
299
- template <class T> inline constexpr bool is_compound_v
300
- = is_compound<T>::value;
301
- template <class T> inline constexpr bool is_member_pointer_v
302
- = is_member_pointer<T>::value;
303
 
304
  // [meta.unary.prop], type properties
305
- template <class T> inline constexpr bool is_const_v
306
- = is_const<T>::value;
307
- template <class T> inline constexpr bool is_volatile_v
308
- = is_volatile<T>::value;
309
- template <class T> inline constexpr bool is_trivial_v
310
- = is_trivial<T>::value;
311
- template <class T> inline constexpr bool is_trivially_copyable_v
312
- = is_trivially_copyable<T>::value;
313
- template <class T> inline constexpr bool is_standard_layout_v
314
- = is_standard_layout<T>::value;
315
- template <class T> inline constexpr bool is_pod_v
316
- = is_pod<T>::value;
317
- template <class T> inline constexpr bool is_empty_v
318
- = is_empty<T>::value;
319
- template <class T> inline constexpr bool is_polymorphic_v
320
- = is_polymorphic<T>::value;
321
- template <class T> inline constexpr bool is_abstract_v
322
- = is_abstract<T>::value;
323
- template <class T> inline constexpr bool is_final_v
324
- = is_final<T>::value;
325
- template <class T> inline constexpr bool is_aggregate_v
326
- = is_aggregate<T>::value;
327
- template <class T> inline constexpr bool is_signed_v
328
- = is_signed<T>::value;
329
- template <class T> inline constexpr bool is_unsigned_v
330
- = is_unsigned<T>::value;
331
- template <class T, class... Args> inline constexpr bool is_constructible_v
332
- = is_constructible<T, Args...>::value;
333
- template <class T> inline constexpr bool is_default_constructible_v
334
- = is_default_constructible<T>::value;
335
- template <class T> inline constexpr bool is_copy_constructible_v
336
- = is_copy_constructible<T>::value;
337
- template <class T> inline constexpr bool is_move_constructible_v
338
- = is_move_constructible<T>::value;
339
- template <class T, class U> inline constexpr bool is_assignable_v
340
- = is_assignable<T, U>::value;
341
- template <class T> inline constexpr bool is_copy_assignable_v
342
- = is_copy_assignable<T>::value;
343
- template <class T> inline constexpr bool is_move_assignable_v
344
- = is_move_assignable<T>::value;
345
- template <class T, class U> inline constexpr bool is_swappable_with_v
346
- = is_swappable_with<T, U>::value;
347
- template <class T> inline constexpr bool is_swappable_v
348
- = is_swappable<T>::value;
349
- template <class T> inline constexpr bool is_destructible_v
350
- = is_destructible<T>::value;
351
- template <class T, class... Args> inline constexpr bool is_trivially_constructible_v
 
 
 
352
  = is_trivially_constructible<T, Args...>::value;
353
- template <class T> inline constexpr bool is_trivially_default_constructible_v
 
354
  = is_trivially_default_constructible<T>::value;
355
- template <class T> inline constexpr bool is_trivially_copy_constructible_v
 
356
  = is_trivially_copy_constructible<T>::value;
357
- template <class T> inline constexpr bool is_trivially_move_constructible_v
 
358
  = is_trivially_move_constructible<T>::value;
359
- template <class T, class U> inline constexpr bool is_trivially_assignable_v
360
- = is_trivially_assignable<T, U>::value;
361
- template <class T> inline constexpr bool is_trivially_copy_assignable_v
 
362
  = is_trivially_copy_assignable<T>::value;
363
- template <class T> inline constexpr bool is_trivially_move_assignable_v
 
364
  = is_trivially_move_assignable<T>::value;
365
- template <class T> inline constexpr bool is_trivially_destructible_v
366
- = is_trivially_destructible<T>::value;
367
- template <class T, class... Args> inline constexpr bool is_nothrow_constructible_v
 
368
  = is_nothrow_constructible<T, Args...>::value;
369
- template <class T> inline constexpr bool is_nothrow_default_constructible_v
 
370
  = is_nothrow_default_constructible<T>::value;
371
- template <class T> inline constexpr bool is_nothrow_copy_constructible_v
 
372
  = is_nothrow_copy_constructible<T>::value;
373
- template <class T> inline constexpr bool is_nothrow_move_constructible_v
 
374
  = is_nothrow_move_constructible<T>::value;
375
- template <class T, class U> inline constexpr bool is_nothrow_assignable_v
376
- = is_nothrow_assignable<T, U>::value;
377
- template <class T> inline constexpr bool is_nothrow_copy_assignable_v
378
- = is_nothrow_copy_assignable<T>::value;
379
- template <class T> inline constexpr bool is_nothrow_move_assignable_v
380
- = is_nothrow_move_assignable<T>::value;
381
- template <class T, class U> inline constexpr bool is_nothrow_swappable_with_v
382
- = is_nothrow_swappable_with<T, U>::value;
383
- template <class T> inline constexpr bool is_nothrow_swappable_v
384
- = is_nothrow_swappable<T>::value;
385
- template <class T> inline constexpr bool is_nothrow_destructible_v
386
- = is_nothrow_destructible<T>::value;
387
- template <class T> inline constexpr bool has_virtual_destructor_v
388
- = has_virtual_destructor<T>::value;
389
- template <class T> inline constexpr bool has_unique_object_representations_v
 
390
  = has_unique_object_representations<T>::value;
391
 
392
  // [meta.unary.prop.query], type property queries
393
- template <class T> inline constexpr size_t alignment_of_v
394
- = alignment_of<T>::value;
395
- template <class T> inline constexpr size_t rank_v
396
- = rank<T>::value;
397
- template <class T, unsigned I = 0> inline constexpr size_t extent_v
398
- = extent<T, I>::value;
399
 
400
  // [meta.rel], type relations
401
- template <class T, class U> inline constexpr bool is_same_v
402
- = is_same<T, U>::value;
403
- template <class Base, class Derived> inline constexpr bool is_base_of_v
404
- = is_base_of<Base, Derived>::value;
405
- template <class From, class To> inline constexpr bool is_convertible_v
406
- = is_convertible<From, To>::value;
407
- template <class Fn, class... ArgTypes> inline constexpr bool is_invocable_v
408
- = is_invocable<Fn, ArgTypes...>::value;
409
- template <class R, class Fn, class... ArgTypes> inline constexpr bool is_invocable_r_v
410
- = is_invocable_r<R, Fn, ArgTypes...>::value;
411
- template <class Fn, class... ArgTypes> inline constexpr bool is_nothrow_invocable_v
412
- = is_nothrow_invocable<Fn, ArgTypes...>::value;
413
- template <class R, class Fn, class... ArgTypes> inline constexpr bool is_nothrow_invocable_r_v
 
 
 
 
 
 
 
 
414
  = is_nothrow_invocable_r<R, Fn, ArgTypes...>::value;
415
 
416
  // [meta.logical], logical operator traits
417
- template<class... B> inline constexpr bool conjunction_v = conjunction<B...>::value;
418
- template<class... B> inline constexpr bool disjunction_v = disjunction<B...>::value;
419
- template<class B> inline constexpr bool negation_v = negation<B>::value;
 
 
 
 
 
 
 
 
 
 
 
 
420
  }
421
  ```
422
 
423
- The behavior of a program that adds specializations for any of the
424
- templates defined in this subclause is undefined unless otherwise
425
- specified.
426
-
427
- Unless otherwise specified, an incomplete type may be used to
428
- instantiate a template in this subclause.
429
-
430
  ### Helper classes <a id="meta.help">[[meta.help]]</a>
431
 
432
  ``` cpp
433
  namespace std {
434
- template <class T, T v>
435
- struct integral_constant {
436
  static constexpr T value = v;
 
437
  using value_type = T;
438
  using type = integral_constant<T, v>;
 
439
  constexpr operator value_type() const noexcept { return value; }
440
  constexpr value_type operator()() const noexcept { return value; }
441
  };
442
  }
443
  ```
@@ -449,29 +509,29 @@ as base classes to define the interface for various type traits.
449
  ### Unary type traits <a id="meta.unary">[[meta.unary]]</a>
450
 
451
  This subclause contains templates that may be used to query the
452
  properties of a type at compile time.
453
 
454
- Each of these templates shall be a `UnaryTypeTrait` ([[meta.rqmts]])
455
  with a base characteristic of `true_type` if the corresponding condition
456
  is `true`, otherwise `false_type`.
457
 
458
  #### Primary type categories <a id="meta.unary.cat">[[meta.unary.cat]]</a>
459
 
460
  The primary type categories correspond to the descriptions given in
461
- section  [[basic.types]] of the C++standard.
462
 
463
  For any given type `T`, the result of applying one of these templates to
464
  `T` and to cv `T` shall yield the same result.
465
 
466
  [*Note 1*: For any given type `T`, exactly one of the primary type
467
  categories has a `value` member that evaluates to `true`. — *end note*]
468
 
469
  #### Composite type traits <a id="meta.unary.comp">[[meta.unary.comp]]</a>
470
 
471
  These templates provide convenient compositions of the primary type
472
- categories, corresponding to the descriptions given in section 
473
  [[basic.types]].
474
 
475
  For any given type `T`, the result of applying one of these templates to
476
  `T` and to cv `T` shall yield the same result.
477
 
@@ -485,16 +545,16 @@ specializations of any of these templates.
485
 
486
  For all of the class templates `X` declared in this subclause,
487
  instantiating that template with a template-argument that is a class
488
  template specialization may result in the implicit instantiation of the
489
  template argument if and only if the semantics of `X` require that the
490
- argument must be a complete type.
491
 
492
  For the purpose of defining the templates in this subclause, a function
493
  call expression `declval<T>()` for any type `T` is considered to be a
494
  trivial ([[basic.types]], [[special]]) function call that is not an
495
- odr-use ([[basic.def.odr]]) of `declval` in the context of the
496
  corresponding definition notwithstanding the restrictions of 
497
  [[declval]].
498
 
499
  [*Note 1*: A union is a class type that can be marked with
500
  `final`. — *end note*]
@@ -575,19 +635,18 @@ if:
575
 
576
  The set of scalar types for which this condition holds is
577
  *implementation-defined*.
578
 
579
  [*Note 4*: If a type has padding bits, the condition does not hold;
580
- otherwise, the condition holds true for unsigned integral
581
- types. — *end note*]
582
 
583
  ### Type property queries <a id="meta.unary.prop.query">[[meta.unary.prop.query]]</a>
584
 
585
  This subclause contains templates that may be used to query properties
586
  of types at compile time.
587
 
588
- Each of these templates shall be a `UnaryTypeTrait` ([[meta.rqmts]])
589
  with a base characteristic of `integral_constant<size_t, Value>`.
590
 
591
  [*Example 1*:
592
 
593
  ``` cpp
@@ -618,21 +677,21 @@ assert((extent_v<int[][4], 1>) == 4);
618
  ### Relationships between types <a id="meta.rel">[[meta.rel]]</a>
619
 
620
  This subclause contains templates that may be used to query
621
  relationships between types at compile time.
622
 
623
- Each of these templates shall be a `BinaryTypeTrait` ([[meta.rqmts]])
624
  with a base characteristic of `true_type` if the corresponding condition
625
  is true, otherwise `false_type`.
626
 
627
  [*Note 1*: Base classes that are private, protected, or ambiguous are,
628
  nonetheless, base classes. — *end note*]
629
 
630
  For the purpose of defining the templates in this subclause, a function
631
  call expression `declval<T>()` for any type `T` is considered to be a
632
  trivial ([[basic.types]], [[special]]) function call that is not an
633
- odr-use ([[basic.def.odr]]) of `declval` in the context of the
634
  corresponding definition notwithstanding the restrictions of 
635
  [[declval]].
636
 
637
  [*Example 1*:
638
 
@@ -663,17 +722,17 @@ implicit conversions to the return type of the function:
663
  To test() {
664
  return declval<From>();
665
  }
666
  ```
667
 
668
- [*Note 2*: This requirement gives well defined results for reference
669
  types, void types, array types, and function types. — *end note*]
670
 
671
  Access checking is performed in a context unrelated to `To` and `From`.
672
  Only the validity of the immediate context of the *expression* of the
673
- `return` statement (including initialization of the returned object or
674
- reference) is considered.
675
 
676
  [*Note 3*: The initialization can result in side effects such as the
677
  instantiation of class template specializations and function template
678
  specializations, the generation of implicitly-defined functions, and so
679
  on. Such side effects are not in the “immediate context” and can result
@@ -683,22 +742,22 @@ in the program being ill-formed. — *end note*]
683
 
684
  This subclause contains templates that may be used to transform one type
685
  to another following some predefined rule.
686
 
687
  Each of the templates in this subclause shall be a
688
- `TransformationTrait` ([[meta.rqmts]]).
689
 
690
  #### Const-volatile modifications <a id="meta.trans.cv">[[meta.trans.cv]]</a>
691
 
692
  [*Example 1*: `remove_const_t<const volatile int>` evaluates to
693
  `volatile int`, whereas `remove_const_t<const int*>` evaluates to
694
  `const int*`. — *end example*]
695
 
696
  #### Reference modifications <a id="meta.trans.ref">[[meta.trans.ref]]</a>
697
 
698
- [*Note 1*: This rule reflects the semantics of reference collapsing (
699
- [[dcl.ref]]). — *end note*]
700
 
701
  #### Sign modifications <a id="meta.trans.sign">[[meta.trans.sign]]</a>
702
 
703
  #### Array modifications <a id="meta.trans.arr">[[meta.trans.arr]]</a>
704
 
@@ -732,16 +791,15 @@ assert((is_same_v<remove_all_extents_t<int[][3]>, int>));
732
 
733
  #### Pointer modifications <a id="meta.trans.ptr">[[meta.trans.ptr]]</a>
734
 
735
  #### Other transformations <a id="meta.trans.other">[[meta.trans.other]]</a>
736
 
737
- [*Note 1*: This behavior is similar to the lvalue-to-rvalue (
738
- [[conv.lval]]), array-to-pointer ([[conv.array]]), and
739
- function-to-pointer ([[conv.func]]) conversions applied when an lvalue
740
- expression is used as an rvalue, but also strips cv-qualifiers from
741
- class types in order to more closely model by-value argument
742
- passing. — *end note*]
743
 
744
  [*Note 2*:
745
 
746
  A typical implementation would define `aligned_storage` as:
747
 
@@ -754,16 +812,51 @@ struct aligned_storage {
754
  };
755
  ```
756
 
757
  — *end note*]
758
 
759
- It is *implementation-defined* whether any extended alignment is
760
- supported ([[basic.align]]).
 
 
761
 
762
- Note A: For the `common_type` trait applied to a parameter pack `T` of
763
- types, the member `type` shall be either defined or not present as
764
- follows:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
765
 
766
  - If `sizeof...(T)` is zero, there shall be no member `type`.
767
  - If `sizeof...(T)` is one, let `T0` denote the sole type constituting
768
  the pack `T`. The member *typedef-name* `type` shall denote the same
769
  type, if any, as `common_type_t<T0, T0>`; otherwise there shall be no
@@ -772,17 +865,22 @@ follows:
772
  `T` be denoted by `T1` and `T2`, respectively, and let `D1` and `D2`
773
  denote the same types as `decay_t<T1>` and `decay_t<T2>`,
774
  respectively.
775
  - If `is_same_v<T1, D1>` is `false` or `is_same_v<T2, D2>` is `false`,
776
  let `C` denote the same type, if any, as `common_type_t<D1, D2>`.
777
- - Otherwise, let `C` denote the same type, if any, as
 
 
778
  ``` cpp
779
  decay_t<decltype(false ? declval<D1>() : declval<D2>())>
780
  ```
781
 
782
- \[*Note 3*: This will not apply if there is a specialization
783
- `common_type<D1, D2>`. — *end note*]
 
 
 
784
 
785
  In either case, the member *typedef-name* `type` shall denote the same
786
  type, if any, as `C`. Otherwise, there shall be no member `type`.
787
  - If `sizeof...(T)` is greater than two, let `T1`, `T2`, and `R`,
788
  respectively, denote the first, second, and (pack of) remaining types
@@ -806,11 +904,59 @@ unambiguous cv-unqualified non-reference type `C` to which each of the
806
  types `T1` and `T2` is explicitly convertible. Moreover,
807
  `common_type_t<T1, T2>` shall denote the same type, if any, as does
808
  `common_type_t<T2, T1>`. No diagnostic is required for a violation of
809
  this Note’s rules.
810
 
811
- [*Example 1*:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
812
 
813
  Given these definitions:
814
 
815
  ``` cpp
816
  using PF1 = bool (&)();
@@ -850,29 +996,29 @@ template<class... B> struct conjunction : see below { };
850
  ```
851
 
852
  The class template `conjunction` forms the logical conjunction of its
853
  template type arguments.
854
 
855
- For a specialization `conjunction<B1, ..., BN>`, if there is a template
856
- type argument `Bi` for which `bool(Bi::value)` is `false`, then
857
- instantiating `conjunction<B1, ..., BN>::value` does not require the
858
- instantiation of `Bj::value` for `j > i`.
859
 
860
  [*Note 1*: This is analogous to the short-circuiting behavior of the
861
  built-in operator `&&`. — *end note*]
862
 
863
- Every template type argument for which `Bi::value` is instantiated shall
864
- be usable as a base class and shall have a member `value` which is
865
  convertible to `bool`, is not hidden, and is unambiguously available in
866
  the type.
867
 
868
- The specialization `conjunction<B1, ..., BN>` has a public and
869
  unambiguous base that is either
870
 
871
- - the first type `Bi` in the list `true_type, B1, ..., BN` for which
872
- `bool(Bi::value)` is `false`, or
873
- - if there is no such `Bi`, the last type in the list.
874
 
875
  [*Note 2*: This means a specialization of `conjunction` does not
876
  necessarily inherit from either `true_type` or
877
  `false_type`. — *end note*]
878
 
@@ -885,29 +1031,29 @@ template<class... B> struct disjunction : see below { };
885
  ```
886
 
887
  The class template `disjunction` forms the logical disjunction of its
888
  template type arguments.
889
 
890
- For a specialization `disjunction<B1, ..., BN>`, if there is a template
891
- type argument `Bi` for which `bool(Bi::value)` is `true`, then
892
- instantiating `disjunction<B1, ..., BN>::value` does not require the
893
- instantiation of `Bj::value` for `j > i`.
894
 
895
  [*Note 3*: This is analogous to the short-circuiting behavior of the
896
  built-in operator `||`. — *end note*]
897
 
898
- Every template type argument for which `Bi::value` is instantiated shall
899
- be usable as a base class and shall have a member `value` which is
900
  convertible to `bool`, is not hidden, and is unambiguously available in
901
  the type.
902
 
903
- The specialization `disjunction<B1, ..., BN>` has a public and
904
  unambiguous base that is either
905
 
906
- - the first type `Bi` in the list `false_type, B1, ..., BN` for which
907
- `bool(Bi::value)` is `true`, or
908
- - if there is no such `Bi`, the last type in the list.
909
 
910
  [*Note 4*: This means a specialization of `disjunction` does not
911
  necessarily inherit from either `true_type` or
912
  `false_type`. — *end note*]
913
 
@@ -918,8 +1064,88 @@ The member names of the base class, other than `disjunction` and
918
  ``` cpp
919
  template<class B> struct negation : see below { };
920
  ```
921
 
922
  The class template `negation` forms the logical negation of its template
923
- type argument. The type `negation<B>` is a `UnaryTypeTrait` with a base
924
- characteristic of `bool_constant<!bool(B::value)>`.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
925
 
 
1
  ## Metaprogramming and type traits <a id="meta">[[meta]]</a>
2
 
3
+ This subclause describes components used by C++ programs, particularly
4
+ in templates, to support the widest possible range of types, optimise
5
  template code usage, detect type related user errors, and perform type
6
  inference and transformation at compile time. It includes type
7
  classification traits, type property inspection traits, and type
8
  transformations. The type classification traits describe a complete
9
  taxonomy of all possible C++ types, and state where in that taxonomy a
10
  given type belongs. The type property inspection traits allow important
11
  characteristics of types or of combinations of types to be inspected.
12
  The type transformations allow certain properties of types to be
13
  manipulated.
14
 
15
+ All functions specified in this subclause are signal-safe
16
+ [[support.signal]].
17
 
18
  ### Requirements <a id="meta.rqmts">[[meta.rqmts]]</a>
19
 
20
+ A describes a property of a type. It shall be a class template that
21
+ takes one template type argument and, optionally, additional arguments
22
+ that help define the property being described. It shall be
23
+ *Cpp17DefaultConstructible*, *Cpp17CopyConstructible*, and publicly and
24
  unambiguously derived, directly or indirectly, from its *base
25
  characteristic*, which is a specialization of the template
26
+ `integral_constant` [[meta.help]], with the arguments to the template
27
  `integral_constant` determined by the requirements for the particular
28
  property being described. The member names of the base characteristic
29
  shall not be hidden and shall be unambiguously available in the
30
+ *Cpp17UnaryTypeTrait*.
31
 
32
+ A describes a relationship between two types. It shall be a class
33
+ template that takes two template type arguments and, optionally,
34
+ additional arguments that help define the relationship being described.
35
+ It shall be *Cpp17DefaultConstructible*, *Cpp17CopyConstructible*, and
36
  publicly and unambiguously derived, directly or indirectly, from its
37
  *base characteristic*, which is a specialization of the template
38
+ `integral_constant` [[meta.help]], with the arguments to the template
39
  `integral_constant` determined by the requirements for the particular
40
  relationship being described. The member names of the base
41
  characteristic shall not be hidden and shall be unambiguously available
42
+ in the *Cpp17BinaryTypeTrait*.
43
 
44
+ A modifies a property of a type. It shall be a class template that takes
45
+ one template type argument and, optionally, additional arguments that
46
+ help define the modification. It shall define a publicly accessible
47
+ nested type named `type`, which shall be a synonym for the modified
48
+ type.
49
+
50
+ Unless otherwise specified, the behavior of a program that adds
51
+ specializations for any of the templates specified in this subclause 
52
+ [[meta]] is undefined.
53
+
54
+ Unless otherwise specified, an incomplete type may be used to
55
+ instantiate a template specified in this subclause. The behavior of a
56
+ program is undefined if:
57
+
58
+ - an instantiation of a template specified in subclause  [[meta]]
59
+ directly or indirectly depends on an incompletely-defined object type
60
+ `T`, and
61
+ - that instantiation could yield a different result were `T`
62
+ hypothetically completed.
63
 
64
  ### Header `<type_traits>` synopsis <a id="meta.type.synop">[[meta.type.synop]]</a>
65
 
66
  ``` cpp
67
  namespace std {
 
102
  template<class T> struct is_const;
103
  template<class T> struct is_volatile;
104
  template<class T> struct is_trivial;
105
  template<class T> struct is_trivially_copyable;
106
  template<class T> struct is_standard_layout;
 
107
  template<class T> struct is_empty;
108
  template<class T> struct is_polymorphic;
109
  template<class T> struct is_abstract;
110
  template<class T> struct is_final;
111
  template<class T> struct is_aggregate;
112
 
113
  template<class T> struct is_signed;
114
  template<class T> struct is_unsigned;
115
+ template<class T> struct is_bounded_array;
116
+ template<class T> struct is_unbounded_array;
117
 
118
  template<class T, class... Args> struct is_constructible;
119
  template<class T> struct is_default_constructible;
120
  template<class T> struct is_copy_constructible;
121
  template<class T> struct is_move_constructible;
 
164
 
165
  // [meta.rel], type relations
166
  template<class T, class U> struct is_same;
167
  template<class Base, class Derived> struct is_base_of;
168
  template<class From, class To> struct is_convertible;
169
+ template<class From, class To> struct is_nothrow_convertible;
170
+ template<class T, class U> struct is_layout_compatible;
171
+ template<class Base, class Derived> struct is_pointer_interconvertible_base_of;
172
 
173
  template<class Fn, class... ArgTypes> struct is_invocable;
174
  template<class R, class Fn, class... ArgTypes> struct is_invocable_r;
175
 
176
  template<class Fn, class... ArgTypes> struct is_nothrow_invocable;
 
235
  using remove_pointer_t = typename remove_pointer<T>::type;
236
  template<class T>
237
  using add_pointer_t = typename add_pointer<T>::type;
238
 
239
  // [meta.trans.other], other transformations
240
+ template<class T> struct type_identity;
241
+ template<size_t Len, size_t Align = default-alignment> // see [meta.trans.other]
242
  struct aligned_storage;
243
  template<size_t Len, class... Types> struct aligned_union;
244
+ template<class T> struct remove_cvref;
245
  template<class T> struct decay;
246
  template<bool, class T = void> struct enable_if;
247
  template<bool, class T, class F> struct conditional;
248
  template<class... T> struct common_type;
249
+ template<class T, class U, template<class> class TQual, template<class> class UQual>
250
+ struct basic_common_reference { };
251
+ template<class... T> struct common_reference;
252
  template<class T> struct underlying_type;
253
  template<class Fn, class... ArgTypes> struct invoke_result;
254
+ template<class T> struct unwrap_reference;
255
+ template<class T> struct unwrap_ref_decay;
256
 
257
+ template<class T>
258
+ using type_identity_t = typename type_identity<T>::type;
259
+ template<size_t Len, size_t Align = default-alignment> // see [meta.trans.other]
260
  using aligned_storage_t = typename aligned_storage<Len, Align>::type;
261
  template<size_t Len, class... Types>
262
  using aligned_union_t = typename aligned_union<Len, Types...>::type;
263
+ template<class T>
264
+ using remove_cvref_t = typename remove_cvref<T>::type;
265
  template<class T>
266
  using decay_t = typename decay<T>::type;
267
  template<bool b, class T = void>
268
  using enable_if_t = typename enable_if<b, T>::type;
269
  template<bool b, class T, class F>
270
  using conditional_t = typename conditional<b, T, F>::type;
271
  template<class... T>
272
  using common_type_t = typename common_type<T...>::type;
273
+ template<class... T>
274
+ using common_reference_t = typename common_reference<T...>::type;
275
  template<class T>
276
  using underlying_type_t = typename underlying_type<T>::type;
277
  template<class Fn, class... ArgTypes>
278
  using invoke_result_t = typename invoke_result<Fn, ArgTypes...>::type;
279
+ template<class T>
280
+ using unwrap_reference_t = typename unwrap_reference<T>::type;
281
+ template<class T>
282
+ using unwrap_ref_decay_t = typename unwrap_ref_decay<T>::type;
283
  template<class...>
284
  using void_t = void;
285
 
286
  // [meta.logical], logical operator traits
287
  template<class... B> struct conjunction;
288
  template<class... B> struct disjunction;
289
  template<class B> struct negation;
290
 
291
  // [meta.unary.cat], primary type categories
292
+ template<class T>
293
+ inline constexpr bool is_void_v = is_void<T>::value;
294
+ template<class T>
295
+ inline constexpr bool is_null_pointer_v = is_null_pointer<T>::value;
296
+ template<class T>
297
+ inline constexpr bool is_integral_v = is_integral<T>::value;
298
+ template<class T>
299
+ inline constexpr bool is_floating_point_v = is_floating_point<T>::value;
300
+ template<class T>
301
+ inline constexpr bool is_array_v = is_array<T>::value;
302
+ template<class T>
303
+ inline constexpr bool is_pointer_v = is_pointer<T>::value;
304
+ template<class T>
305
+ inline constexpr bool is_lvalue_reference_v = is_lvalue_reference<T>::value;
306
+ template<class T>
307
+ inline constexpr bool is_rvalue_reference_v = is_rvalue_reference<T>::value;
308
+ template<class T>
309
+ inline constexpr bool is_member_object_pointer_v = is_member_object_pointer<T>::value;
310
+ template<class T>
311
+ inline constexpr bool is_member_function_pointer_v = is_member_function_pointer<T>::value;
312
+ template<class T>
313
+ inline constexpr bool is_enum_v = is_enum<T>::value;
314
+ template<class T>
315
+ inline constexpr bool is_union_v = is_union<T>::value;
316
+ template<class T>
317
+ inline constexpr bool is_class_v = is_class<T>::value;
318
+ template<class T>
319
+ inline constexpr bool is_function_v = is_function<T>::value;
320
 
321
  // [meta.unary.comp], composite type categories
322
+ template<class T>
323
+ inline constexpr bool is_reference_v = is_reference<T>::value;
324
+ template<class T>
325
+ inline constexpr bool is_arithmetic_v = is_arithmetic<T>::value;
326
+ template<class T>
327
+ inline constexpr bool is_fundamental_v = is_fundamental<T>::value;
328
+ template<class T>
329
+ inline constexpr bool is_object_v = is_object<T>::value;
330
+ template<class T>
331
+ inline constexpr bool is_scalar_v = is_scalar<T>::value;
332
+ template<class T>
333
+ inline constexpr bool is_compound_v = is_compound<T>::value;
334
+ template<class T>
335
+ inline constexpr bool is_member_pointer_v = is_member_pointer<T>::value;
336
 
337
  // [meta.unary.prop], type properties
338
+ template<class T>
339
+ inline constexpr bool is_const_v = is_const<T>::value;
340
+ template<class T>
341
+ inline constexpr bool is_volatile_v = is_volatile<T>::value;
342
+ template<class T>
343
+ inline constexpr bool is_trivial_v = is_trivial<T>::value;
344
+ template<class T>
345
+ inline constexpr bool is_trivially_copyable_v = is_trivially_copyable<T>::value;
346
+ template<class T>
347
+ inline constexpr bool is_standard_layout_v = is_standard_layout<T>::value;
348
+ template<class T>
349
+ inline constexpr bool is_empty_v = is_empty<T>::value;
350
+ template<class T>
351
+ inline constexpr bool is_polymorphic_v = is_polymorphic<T>::value;
352
+ template<class T>
353
+ inline constexpr bool is_abstract_v = is_abstract<T>::value;
354
+ template<class T>
355
+ inline constexpr bool is_final_v = is_final<T>::value;
356
+ template<class T>
357
+ inline constexpr bool is_aggregate_v = is_aggregate<T>::value;
358
+ template<class T>
359
+ inline constexpr bool is_signed_v = is_signed<T>::value;
360
+ template<class T>
361
+ inline constexpr bool is_unsigned_v = is_unsigned<T>::value;
362
+ template<class T>
363
+ inline constexpr bool is_bounded_array_v = is_bounded_array<T>::value;
364
+ template<class T>
365
+ inline constexpr bool is_unbounded_array_v = is_unbounded_array<T>::value;
366
+ template<class T, class... Args>
367
+ inline constexpr bool is_constructible_v = is_constructible<T, Args...>::value;
368
+ template<class T>
369
+ inline constexpr bool is_default_constructible_v = is_default_constructible<T>::value;
370
+ template<class T>
371
+ inline constexpr bool is_copy_constructible_v = is_copy_constructible<T>::value;
372
+ template<class T>
373
+ inline constexpr bool is_move_constructible_v = is_move_constructible<T>::value;
374
+ template<class T, class U>
375
+ inline constexpr bool is_assignable_v = is_assignable<T, U>::value;
376
+ template<class T>
377
+ inline constexpr bool is_copy_assignable_v = is_copy_assignable<T>::value;
378
+ template<class T>
379
+ inline constexpr bool is_move_assignable_v = is_move_assignable<T>::value;
380
+ template<class T, class U>
381
+ inline constexpr bool is_swappable_with_v = is_swappable_with<T, U>::value;
382
+ template<class T>
383
+ inline constexpr bool is_swappable_v = is_swappable<T>::value;
384
+ template<class T>
385
+ inline constexpr bool is_destructible_v = is_destructible<T>::value;
386
+ template<class T, class... Args>
387
+ inline constexpr bool is_trivially_constructible_v
388
  = is_trivially_constructible<T, Args...>::value;
389
+ template<class T>
390
+ inline constexpr bool is_trivially_default_constructible_v
391
  = is_trivially_default_constructible<T>::value;
392
+ template<class T>
393
+ inline constexpr bool is_trivially_copy_constructible_v
394
  = is_trivially_copy_constructible<T>::value;
395
+ template<class T>
396
+ inline constexpr bool is_trivially_move_constructible_v
397
  = is_trivially_move_constructible<T>::value;
398
+ template<class T, class U>
399
+ inline constexpr bool is_trivially_assignable_v = is_trivially_assignable<T, U>::value;
400
+ template<class T>
401
+ inline constexpr bool is_trivially_copy_assignable_v
402
  = is_trivially_copy_assignable<T>::value;
403
+ template<class T>
404
+ inline constexpr bool is_trivially_move_assignable_v
405
  = is_trivially_move_assignable<T>::value;
406
+ template<class T>
407
+ inline constexpr bool is_trivially_destructible_v = is_trivially_destructible<T>::value;
408
+ template<class T, class... Args>
409
+ inline constexpr bool is_nothrow_constructible_v
410
  = is_nothrow_constructible<T, Args...>::value;
411
+ template<class T>
412
+ inline constexpr bool is_nothrow_default_constructible_v
413
  = is_nothrow_default_constructible<T>::value;
414
+ template<class T>
415
+ inline constexpr bool is_nothrow_copy_constructible_v
416
  = is_nothrow_copy_constructible<T>::value;
417
+ template<class T>
418
+ inline constexpr bool is_nothrow_move_constructible_v
419
  = is_nothrow_move_constructible<T>::value;
420
+ template<class T, class U>
421
+ inline constexpr bool is_nothrow_assignable_v = is_nothrow_assignable<T, U>::value;
422
+ template<class T>
423
+ inline constexpr bool is_nothrow_copy_assignable_v = is_nothrow_copy_assignable<T>::value;
424
+ template<class T>
425
+ inline constexpr bool is_nothrow_move_assignable_v = is_nothrow_move_assignable<T>::value;
426
+ template<class T, class U>
427
+ inline constexpr bool is_nothrow_swappable_with_v = is_nothrow_swappable_with<T, U>::value;
428
+ template<class T>
429
+ inline constexpr bool is_nothrow_swappable_v = is_nothrow_swappable<T>::value;
430
+ template<class T>
431
+ inline constexpr bool is_nothrow_destructible_v = is_nothrow_destructible<T>::value;
432
+ template<class T>
433
+ inline constexpr bool has_virtual_destructor_v = has_virtual_destructor<T>::value;
434
+ template<class T>
435
+ inline constexpr bool has_unique_object_representations_v
436
  = has_unique_object_representations<T>::value;
437
 
438
  // [meta.unary.prop.query], type property queries
439
+ template<class T>
440
+ inline constexpr size_t alignment_of_v = alignment_of<T>::value;
441
+ template<class T>
442
+ inline constexpr size_t rank_v = rank<T>::value;
443
+ template<class T, unsigned I = 0>
444
+ inline constexpr size_t extent_v = extent<T, I>::value;
445
 
446
  // [meta.rel], type relations
447
+ template<class T, class U>
448
+ inline constexpr bool is_same_v = is_same<T, U>::value;
449
+ template<class Base, class Derived>
450
+ inline constexpr bool is_base_of_v = is_base_of<Base, Derived>::value;
451
+ template<class From, class To>
452
+ inline constexpr bool is_convertible_v = is_convertible<From, To>::value;
453
+ template<class From, class To>
454
+ inline constexpr bool is_nothrow_convertible_v = is_nothrow_convertible<From, To>::value;
455
+ template<class T, class U>
456
+ inline constexpr bool is_layout_compatible_v = is_layout_compatible<T, U>::value;
457
+ template<class Base, class Derived>
458
+ inline constexpr bool is_pointer_interconvertible_base_of_v
459
+ = is_pointer_interconvertible_base_of<Base, Derived>::value;
460
+ template<class Fn, class... ArgTypes>
461
+ inline constexpr bool is_invocable_v = is_invocable<Fn, ArgTypes...>::value;
462
+ template<class R, class Fn, class... ArgTypes>
463
+ inline constexpr bool is_invocable_r_v = is_invocable_r<R, Fn, ArgTypes...>::value;
464
+ template<class Fn, class... ArgTypes>
465
+ inline constexpr bool is_nothrow_invocable_v = is_nothrow_invocable<Fn, ArgTypes...>::value;
466
+ template<class R, class Fn, class... ArgTypes>
467
+ inline constexpr bool is_nothrow_invocable_r_v
468
  = is_nothrow_invocable_r<R, Fn, ArgTypes...>::value;
469
 
470
  // [meta.logical], logical operator traits
471
+ template<class... B>
472
+ inline constexpr bool conjunction_v = conjunction<B...>::value;
473
+ template<class... B>
474
+ inline constexpr bool disjunction_v = disjunction<B...>::value;
475
+ template<class B>
476
+ inline constexpr bool negation_v = negation<B>::value;
477
+
478
+ // [meta.member], member relationships
479
+ template<class S, class M>
480
+ constexpr bool is_pointer_interconvertible_with_class(M S::*m) noexcept;
481
+ template<class S1, class S2, class M1, class M2>
482
+ constexpr bool is_corresponding_member(M1 S1::*m1, M2 S2::*m2) noexcept;
483
+
484
+ // [meta.const.eval], constant evaluation context
485
+ constexpr bool is_constant_evaluated() noexcept;
486
  }
487
  ```
488
 
 
 
 
 
 
 
 
489
  ### Helper classes <a id="meta.help">[[meta.help]]</a>
490
 
491
  ``` cpp
492
  namespace std {
493
+ template<class T, T v> struct integral_constant {
 
494
  static constexpr T value = v;
495
+
496
  using value_type = T;
497
  using type = integral_constant<T, v>;
498
+
499
  constexpr operator value_type() const noexcept { return value; }
500
  constexpr value_type operator()() const noexcept { return value; }
501
  };
502
  }
503
  ```
 
509
  ### Unary type traits <a id="meta.unary">[[meta.unary]]</a>
510
 
511
  This subclause contains templates that may be used to query the
512
  properties of a type at compile time.
513
 
514
+ Each of these templates shall be a *Cpp17UnaryTypeTrait* [[meta.rqmts]]
515
  with a base characteristic of `true_type` if the corresponding condition
516
  is `true`, otherwise `false_type`.
517
 
518
  #### Primary type categories <a id="meta.unary.cat">[[meta.unary.cat]]</a>
519
 
520
  The primary type categories correspond to the descriptions given in
521
+ subclause  [[basic.types]] of the C++ standard.
522
 
523
  For any given type `T`, the result of applying one of these templates to
524
  `T` and to cv `T` shall yield the same result.
525
 
526
  [*Note 1*: For any given type `T`, exactly one of the primary type
527
  categories has a `value` member that evaluates to `true`. — *end note*]
528
 
529
  #### Composite type traits <a id="meta.unary.comp">[[meta.unary.comp]]</a>
530
 
531
  These templates provide convenient compositions of the primary type
532
+ categories, corresponding to the descriptions given in subclause 
533
  [[basic.types]].
534
 
535
  For any given type `T`, the result of applying one of these templates to
536
  `T` and to cv `T` shall yield the same result.
537
 
 
545
 
546
  For all of the class templates `X` declared in this subclause,
547
  instantiating that template with a template-argument that is a class
548
  template specialization may result in the implicit instantiation of the
549
  template argument if and only if the semantics of `X` require that the
550
+ argument is a complete type.
551
 
552
  For the purpose of defining the templates in this subclause, a function
553
  call expression `declval<T>()` for any type `T` is considered to be a
554
  trivial ([[basic.types]], [[special]]) function call that is not an
555
+ odr-use [[basic.def.odr]] of `declval` in the context of the
556
  corresponding definition notwithstanding the restrictions of 
557
  [[declval]].
558
 
559
  [*Note 1*: A union is a class type that can be marked with
560
  `final`. — *end note*]
 
635
 
636
  The set of scalar types for which this condition holds is
637
  *implementation-defined*.
638
 
639
  [*Note 4*: If a type has padding bits, the condition does not hold;
640
+ otherwise, the condition holds true for integral types. — *end note*]
 
641
 
642
  ### Type property queries <a id="meta.unary.prop.query">[[meta.unary.prop.query]]</a>
643
 
644
  This subclause contains templates that may be used to query properties
645
  of types at compile time.
646
 
647
+ Each of these templates shall be a *Cpp17UnaryTypeTrait* [[meta.rqmts]]
648
  with a base characteristic of `integral_constant<size_t, Value>`.
649
 
650
  [*Example 1*:
651
 
652
  ``` cpp
 
677
  ### Relationships between types <a id="meta.rel">[[meta.rel]]</a>
678
 
679
  This subclause contains templates that may be used to query
680
  relationships between types at compile time.
681
 
682
+ Each of these templates shall be a *Cpp17BinaryTypeTrait* [[meta.rqmts]]
683
  with a base characteristic of `true_type` if the corresponding condition
684
  is true, otherwise `false_type`.
685
 
686
  [*Note 1*: Base classes that are private, protected, or ambiguous are,
687
  nonetheless, base classes. — *end note*]
688
 
689
  For the purpose of defining the templates in this subclause, a function
690
  call expression `declval<T>()` for any type `T` is considered to be a
691
  trivial ([[basic.types]], [[special]]) function call that is not an
692
+ odr-use [[basic.def.odr]] of `declval` in the context of the
693
  corresponding definition notwithstanding the restrictions of 
694
  [[declval]].
695
 
696
  [*Example 1*:
697
 
 
722
  To test() {
723
  return declval<From>();
724
  }
725
  ```
726
 
727
+ [*Note 2*: This requirement gives well-defined results for reference
728
  types, void types, array types, and function types. — *end note*]
729
 
730
  Access checking is performed in a context unrelated to `To` and `From`.
731
  Only the validity of the immediate context of the *expression* of the
732
+ `return` statement [[stmt.return]] (including initialization of the
733
+ returned object or reference) is considered.
734
 
735
  [*Note 3*: The initialization can result in side effects such as the
736
  instantiation of class template specializations and function template
737
  specializations, the generation of implicitly-defined functions, and so
738
  on. Such side effects are not in the “immediate context” and can result
 
742
 
743
  This subclause contains templates that may be used to transform one type
744
  to another following some predefined rule.
745
 
746
  Each of the templates in this subclause shall be a
747
+ *Cpp17TransformationTrait* [[meta.rqmts]].
748
 
749
  #### Const-volatile modifications <a id="meta.trans.cv">[[meta.trans.cv]]</a>
750
 
751
  [*Example 1*: `remove_const_t<const volatile int>` evaluates to
752
  `volatile int`, whereas `remove_const_t<const int*>` evaluates to
753
  `const int*`. — *end example*]
754
 
755
  #### Reference modifications <a id="meta.trans.ref">[[meta.trans.ref]]</a>
756
 
757
+ [*Note 1*: This rule reflects the semantics of reference collapsing
758
+ [[dcl.ref]]. — *end note*]
759
 
760
  #### Sign modifications <a id="meta.trans.sign">[[meta.trans.sign]]</a>
761
 
762
  #### Array modifications <a id="meta.trans.arr">[[meta.trans.arr]]</a>
763
 
 
791
 
792
  #### Pointer modifications <a id="meta.trans.ptr">[[meta.trans.ptr]]</a>
793
 
794
  #### Other transformations <a id="meta.trans.other">[[meta.trans.other]]</a>
795
 
796
+ [*Note 1*: This behavior is similar to the lvalue-to-rvalue
797
+ [[conv.lval]], array-to-pointer [[conv.array]], and function-to-pointer
798
+ [[conv.func]] conversions applied when an lvalue is used as an rvalue,
799
+ but also strips cv-qualifiers from class types in order to more closely
800
+ model by-value argument passing. — *end note*]
 
801
 
802
  [*Note 2*:
803
 
804
  A typical implementation would define `aligned_storage` as:
805
 
 
812
  };
813
  ```
814
 
815
  — *end note*]
816
 
817
+ In addition to being available via inclusion of the `<type_traits>`
818
+ header, the templates `unwrap_reference`, `unwrap_ref_decay`,
819
+ `unwrap_reference_t`, and `unwrap_ref_decay_t` are available when the
820
+ header `<functional>` [[functional.syn]] is included.
821
 
822
+ Let:
823
+
824
+ - `CREF(A)` be `add_lvalue_reference_t<const remove_reference_t<A>{}>`,
825
+ - `XREF(A)` denote a unary alias template `T` such that `T<U>` denotes
826
+ the same type as `U` with the addition of `A`’s cv and reference
827
+ qualifiers, for a non-reference cv-unqualified type `U`,
828
+ - `COPYCV(FROM, TO)` be an alias for type `TO` with the addition of
829
+ `FROM`’s top-level cv-qualifiers,
830
+ \[*Example 1*: `COPYCV(const int, volatile short)` is an alias for
831
+ `const volatile short`. — *end example*]
832
+ - `COND-RES(X, Y)` be
833
+ `decltype(false ? declval<X(&)()>()() : declval<Y(&)()>()())`.
834
+
835
+ Given types `A` and `B`, let `X` be `remove_reference_t<A>`, let `Y` be
836
+ `remove_reference_t<B>`, and let `COMMON-{REF}(A, B)` be:
837
+
838
+ - If `A` and `B` are both lvalue reference types, `COMMON-REF(A, B)` is
839
+ `COND-RES(COPYCV(X, Y) &,
840
+ COPYCV({}Y, X) &)` if that type exists and is a reference type.
841
+ - Otherwise, let `C` be `remove_reference_t<COMMON-REF(X&, Y&)>&&`. If
842
+ `A` and `B` are both rvalue reference types, `C` is well-formed, and
843
+ `is_convertible_v<A, C> && is_convertible_v<B, C>` is `true`, then
844
+ `COMMON-REF(A, B)` is `C`.
845
+ - Otherwise, let `D` be `COMMON-REF(const X&, Y&)`. If `A` is an rvalue
846
+ reference and `B` is an lvalue reference and `D` is well-formed and
847
+ `is_convertible_v<A, D>` is `true`, then `COMMON-REF(A, B)` is `D`.
848
+ - Otherwise, if `A` is an lvalue reference and `B` is an rvalue
849
+ reference, then `COMMON-REF(A, B)` is `COMMON-REF(B, A)`.
850
+ - Otherwise, `COMMON-REF(A, B)` is ill-formed.
851
+
852
+ If any of the types computed above is ill-formed, then
853
+ `COMMON-REF(A, B)` is ill-formed.
854
+
855
+ Note A: For the `common_type` trait applied to a template parameter pack
856
+ `T` of types, the member `type` shall be either defined or not present
857
+ as follows:
858
 
859
  - If `sizeof...(T)` is zero, there shall be no member `type`.
860
  - If `sizeof...(T)` is one, let `T0` denote the sole type constituting
861
  the pack `T`. The member *typedef-name* `type` shall denote the same
862
  type, if any, as `common_type_t<T0, T0>`; otherwise there shall be no
 
865
  `T` be denoted by `T1` and `T2`, respectively, and let `D1` and `D2`
866
  denote the same types as `decay_t<T1>` and `decay_t<T2>`,
867
  respectively.
868
  - If `is_same_v<T1, D1>` is `false` or `is_same_v<T2, D2>` is `false`,
869
  let `C` denote the same type, if any, as `common_type_t<D1, D2>`.
870
+ - \[*Note 3*: None of the following will apply if there is a
871
+ specialization `common_type<D1, D2>`. — *end note*]
872
+ - Otherwise, if
873
  ``` cpp
874
  decay_t<decltype(false ? declval<D1>() : declval<D2>())>
875
  ```
876
 
877
+ denotes a valid type, let `C` denote that type.
878
+ - Otherwise, if `COND-RES(CREF(D1),
879
+ CREF(D2))` denotes a type, let `C` denote the type
880
+ `decay_t<COND-RES(CREF(D1),
881
+ CREF(D2))>`.
882
 
883
  In either case, the member *typedef-name* `type` shall denote the same
884
  type, if any, as `C`. Otherwise, there shall be no member `type`.
885
  - If `sizeof...(T)` is greater than two, let `T1`, `T2`, and `R`,
886
  respectively, denote the first, second, and (pack of) remaining types
 
904
  types `T1` and `T2` is explicitly convertible. Moreover,
905
  `common_type_t<T1, T2>` shall denote the same type, if any, as does
906
  `common_type_t<T2, T1>`. No diagnostic is required for a violation of
907
  this Note’s rules.
908
 
909
+ Note C: For the `common_reference` trait applied to a parameter pack `T`
910
+ of types, the member `type` shall be either defined or not present as
911
+ follows:
912
+
913
+ - If `sizeof...(T)` is zero, there shall be no member `type`.
914
+ - Otherwise, if `sizeof...(T)` is one, let `T0` denote the sole type in
915
+ the pack `T`. The member typedef `type` shall denote the same type as
916
+ `T0`.
917
+ - Otherwise, if `sizeof...(T)` is two, let `T1` and `T2` denote the two
918
+ types in the pack `T`. Then
919
+ - If `T1` and `T2` are reference types and `COMMON-REF(T1, T2)` is
920
+ well-formed, then the member typedef `type` denotes that type.
921
+ - Otherwise, if
922
+ `basic_common_reference<remove_cvref_t<T1>, remove_cvref_t<T2>,
923
+ {}XREF({}T1), XREF(T2)>::type` is well-formed, then the member
924
+ typedef `type` denotes that type.
925
+ - Otherwise, if `COND-RES(T1, T2)` is well-formed, then the member
926
+ typedef `type` denotes that type.
927
+ - Otherwise, if `common_type_t<T1, T2>` is well-formed, then the
928
+ member typedef `type` denotes that type.
929
+ - Otherwise, there shall be no member `type`.
930
+ - Otherwise, if `sizeof...(T)` is greater than two, let `T1`, `T2`, and
931
+ `Rest`, respectively, denote the first, second, and (pack of)
932
+ remaining types comprising `T`. Let `C` be the type
933
+ `common_reference_t<T1, T2>`. Then:
934
+ - If there is such a type `C`, the member typedef `type` shall denote
935
+ the same type, if any, as `common_reference_t<C, Rest...>`.
936
+ - Otherwise, there shall be no member `type`.
937
+
938
+ Note D: Notwithstanding the provisions of [[meta.type.synop]], and
939
+ pursuant to [[namespace.std]], a program may partially specialize
940
+ `basic_common_reference<T, U, TQual, UQual>` for types `T` and `U` such
941
+ that `is_same_v<T, decay_t<T>{>}` and `is_same_v<U, decay_t<U>{>}` are
942
+ each `true`.
943
+
944
+ [*Note 5*: Such specializations can be used to influence the result of
945
+ `common_reference`, and are needed when only explicit conversions are
946
+ desired between the template arguments. — *end note*]
947
+
948
+ Such a specialization need not have a member named `type`, but if it
949
+ does, that member shall be a *typedef-name* for an accessible and
950
+ unambiguous type `C` to which each of the types `TQual<T>` and
951
+ `UQual<U>` is convertible. Moreover,
952
+ `basic_common_reference<T, U, TQual, UQual>::type` shall denote the same
953
+ type, if any, as does
954
+ `basic_common_reference<U, T, UQual, TQual>::type`. No diagnostic is
955
+ required for a violation of these rules.
956
+
957
+ [*Example 2*:
958
 
959
  Given these definitions:
960
 
961
  ``` cpp
962
  using PF1 = bool (&)();
 
996
  ```
997
 
998
  The class template `conjunction` forms the logical conjunction of its
999
  template type arguments.
1000
 
1001
+ For a specialization `conjunction<``B₁``, `…`, ``B_N``>`, if there is a
1002
+ template type argument `Bᵢ` for which `bool(``Bᵢ``::value)` is `false`,
1003
+ then instantiating `conjunction<``B₁``, `…`, ``B_N``>::value` does not
1004
+ require the instantiation of `Bⱼ``::value` for j > i.
1005
 
1006
  [*Note 1*: This is analogous to the short-circuiting behavior of the
1007
  built-in operator `&&`. — *end note*]
1008
 
1009
+ Every template type argument for which `Bᵢ``::value` is instantiated
1010
+ shall be usable as a base class and shall have a member `value` which is
1011
  convertible to `bool`, is not hidden, and is unambiguously available in
1012
  the type.
1013
 
1014
+ The specialization `conjunction<``B₁``, `…`, ``B_N``>` has a public and
1015
  unambiguous base that is either
1016
 
1017
+ - the first type `Bᵢ` in the list `true_type, ``B₁``, `…`, ``B_N` for
1018
+ which `bool(``Bᵢ``::value)` is `false`, or
1019
+ - if there is no such `Bᵢ`, the last type in the list.
1020
 
1021
  [*Note 2*: This means a specialization of `conjunction` does not
1022
  necessarily inherit from either `true_type` or
1023
  `false_type`. — *end note*]
1024
 
 
1031
  ```
1032
 
1033
  The class template `disjunction` forms the logical disjunction of its
1034
  template type arguments.
1035
 
1036
+ For a specialization `disjunction<``B₁``, `…`, ``B_N``>`, if there is a
1037
+ template type argument `Bᵢ` for which `bool(``Bᵢ``::value)` is `true`,
1038
+ then instantiating `disjunction<``B₁``, `…`, ``B_N``>::value` does not
1039
+ require the instantiation of `Bⱼ``::value` for j > i.
1040
 
1041
  [*Note 3*: This is analogous to the short-circuiting behavior of the
1042
  built-in operator `||`. — *end note*]
1043
 
1044
+ Every template type argument for which `Bᵢ``::value` is instantiated
1045
+ shall be usable as a base class and shall have a member `value` which is
1046
  convertible to `bool`, is not hidden, and is unambiguously available in
1047
  the type.
1048
 
1049
+ The specialization `disjunction<``B₁``, `…`, ``B_N``>` has a public and
1050
  unambiguous base that is either
1051
 
1052
+ - the first type `Bᵢ` in the list `false_type, ``B₁``, `…`, ``B_N` for
1053
+ which `bool(``Bᵢ``::value)` is `true`, or
1054
+ - if there is no such `Bᵢ`, the last type in the list.
1055
 
1056
  [*Note 4*: This means a specialization of `disjunction` does not
1057
  necessarily inherit from either `true_type` or
1058
  `false_type`. — *end note*]
1059
 
 
1064
  ``` cpp
1065
  template<class B> struct negation : see below { };
1066
  ```
1067
 
1068
  The class template `negation` forms the logical negation of its template
1069
+ type argument. The type `negation<B>` is a *Cpp17UnaryTypeTrait* with a
1070
+ base characteristic of `bool_constant<!bool(B::value)>`.
1071
+
1072
+ ### Member relationships <a id="meta.member">[[meta.member]]</a>
1073
+
1074
+ ``` cpp
1075
+ template<class S, class M>
1076
+ constexpr bool is_pointer_interconvertible_with_class(M S::*m) noexcept;
1077
+ ```
1078
+
1079
+ *Mandates:* `S` is a complete type.
1080
+
1081
+ *Returns:* `true` if and only if `S` is a standard-layout type, `M` is
1082
+ an object type, `m` is not null, and each object `s` of type `S` is
1083
+ pointer-interconvertible [[basic.compound]] with its subobject `s.*m`.
1084
+
1085
+ ``` cpp
1086
+ template<class S1, class S2, class M1, class M2>
1087
+ constexpr bool is_corresponding_member(M1 S1::*m1, M2 S2::*m2) noexcept;
1088
+ ```
1089
+
1090
+ *Mandates:* `S1` and `S2` are complete types.
1091
+
1092
+ *Returns:* `true` if and only if `S1` and `S2` are standard-layout
1093
+ types, `M1` and `M2` are object types, `m1` and `m2` are not null, and
1094
+ `m1` and `m2` point to corresponding members of the common initial
1095
+ sequence [[class.mem]] of `S1` and `S2`.
1096
+
1097
+ [*Note 1*:
1098
+
1099
+ The type of a pointer-to-member expression `&C::b` is not always a
1100
+ pointer to member of `C`, leading to potentially surprising results when
1101
+ using these functions in conjunction with inheritance.
1102
+
1103
+ [*Example 1*:
1104
+
1105
+ ``` cpp
1106
+ struct A { int a; }; // a standard-layout class
1107
+ struct B { int b; }; // a standard-layout class
1108
+ struct C: public A, public B { }; // not a standard-layout class
1109
+
1110
+ static_assert( is_pointer_interconvertible_with_class( &C::b ) );
1111
+ // Succeeds because, despite its appearance, &C::b has type
1112
+ // ``pointer to member of B of type int''.
1113
+ static_assert( is_pointer_interconvertible_with_class<C>( &C::b ) );
1114
+ // Forces the use of class C, and fails.
1115
+
1116
+ static_assert( is_corresponding_member( &C::a, &C::b ) );
1117
+ // Succeeds because, despite its appearance, &C::a and &C::b have types
1118
+ // ``pointer to member of A of type int'' and
1119
+ // ``pointer to member of B of type int'', respectively.
1120
+ static_assert( is_corresponding_member<C, C>( &C::a, &C::b ) );
1121
+ // Forces the use of class C, and fails.
1122
+ ```
1123
+
1124
+ — *end example*]
1125
+
1126
+ — *end note*]
1127
+
1128
+ ### Constant evaluation context <a id="meta.const.eval">[[meta.const.eval]]</a>
1129
+
1130
+ ``` cpp
1131
+ constexpr bool is_constant_evaluated() noexcept;
1132
+ ```
1133
+
1134
+ *Returns:* `true` if and only if evaluation of the call occurs within
1135
+ the evaluation of an expression or conversion that is manifestly
1136
+ constant-evaluated [[expr.const]].
1137
+
1138
+ [*Example 1*:
1139
+
1140
+ ``` cpp
1141
+ constexpr void f(unsigned char *p, int n) {
1142
+ if (std::is_constant_evaluated()) { // should not be a constexpr if statement
1143
+ for (int k = 0; k<n; ++k) p[k] = 0;
1144
+ } else {
1145
+ memset(p, 0, n); // not a core constant expression
1146
+ }
1147
+ }
1148
+ ```
1149
+
1150
+ — *end example*]
1151