- tmp/tmp0zp6zs62/{from.md → to.md} +518 -185
tmp/tmp0zp6zs62/{from.md → to.md}
RENAMED
|
@@ -1,20 +1,81 @@
|
|
| 1 |
-
#
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
|
@@ -46,26 +107,26 @@ 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
|
| 52 |
-
|
| 53 |
|
| 54 |
Unless otherwise specified, an incomplete type may be used to
|
| 55 |
-
instantiate a template specified in
|
| 56 |
program is undefined if:
|
| 57 |
|
| 58 |
-
- an instantiation of a template specified in
|
| 59 |
-
|
| 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 {
|
| 68 |
// [meta.help], helper class
|
| 69 |
template<class T, T v> struct integral_constant;
|
| 70 |
|
| 71 |
template<bool B>
|
|
@@ -112,10 +173,11 @@ namespace std {
|
|
| 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;
|
|
@@ -151,14 +213,19 @@ namespace std {
|
|
| 151 |
template<class T, class U> struct is_nothrow_swappable_with;
|
| 152 |
template<class T> struct is_nothrow_swappable;
|
| 153 |
|
| 154 |
template<class T> struct is_nothrow_destructible;
|
| 155 |
|
|
|
|
|
|
|
| 156 |
template<class T> struct has_virtual_destructor;
|
| 157 |
|
| 158 |
template<class T> struct has_unique_object_representations;
|
| 159 |
|
|
|
|
|
|
|
|
|
|
| 160 |
// [meta.unary.prop.query], type property queries
|
| 161 |
template<class T> struct alignment_of;
|
| 162 |
template<class T> struct rank;
|
| 163 |
template<class T, unsigned I = 0> struct extent;
|
| 164 |
|
|
@@ -236,13 +303,10 @@ namespace std {
|
|
| 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;
|
|
@@ -254,22 +318,18 @@ namespace std {
|
|
| 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
|
| 268 |
-
using enable_if_t = typename enable_if<
|
| 269 |
-
template<bool
|
| 270 |
-
using conditional_t = typename conditional<
|
| 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>
|
|
@@ -288,194 +348,204 @@ namespace std {
|
|
| 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 |
-
|
| 294 |
template<class T>
|
| 295 |
-
|
| 296 |
template<class T>
|
| 297 |
-
|
| 298 |
template<class T>
|
| 299 |
-
|
| 300 |
template<class T>
|
| 301 |
-
|
| 302 |
template<class T>
|
| 303 |
-
|
| 304 |
template<class T>
|
| 305 |
-
|
| 306 |
template<class T>
|
| 307 |
-
|
| 308 |
template<class T>
|
| 309 |
-
|
| 310 |
template<class T>
|
| 311 |
-
|
| 312 |
template<class T>
|
| 313 |
-
|
| 314 |
template<class T>
|
| 315 |
-
|
| 316 |
template<class T>
|
| 317 |
-
|
| 318 |
template<class T>
|
| 319 |
-
|
| 320 |
|
| 321 |
// [meta.unary.comp], composite type categories
|
| 322 |
template<class T>
|
| 323 |
-
|
| 324 |
template<class T>
|
| 325 |
-
|
| 326 |
template<class T>
|
| 327 |
-
|
| 328 |
template<class T>
|
| 329 |
-
|
| 330 |
template<class T>
|
| 331 |
-
|
| 332 |
template<class T>
|
| 333 |
-
|
| 334 |
template<class T>
|
| 335 |
-
|
| 336 |
|
| 337 |
// [meta.unary.prop], type properties
|
| 338 |
template<class T>
|
| 339 |
-
|
| 340 |
template<class T>
|
| 341 |
-
|
| 342 |
template<class T>
|
| 343 |
-
|
| 344 |
template<class T>
|
| 345 |
-
|
| 346 |
template<class T>
|
| 347 |
-
|
| 348 |
template<class T>
|
| 349 |
-
|
| 350 |
template<class T>
|
| 351 |
-
|
| 352 |
template<class T>
|
| 353 |
-
|
| 354 |
template<class T>
|
| 355 |
-
|
| 356 |
template<class T>
|
| 357 |
-
|
| 358 |
template<class T>
|
| 359 |
-
|
| 360 |
template<class T>
|
| 361 |
-
|
| 362 |
template<class T>
|
| 363 |
-
|
| 364 |
template<class T>
|
| 365 |
-
|
|
|
|
|
|
|
| 366 |
template<class T, class... Args>
|
| 367 |
-
|
| 368 |
template<class T>
|
| 369 |
-
|
| 370 |
template<class T>
|
| 371 |
-
|
| 372 |
template<class T>
|
| 373 |
-
|
| 374 |
template<class T, class U>
|
| 375 |
-
|
| 376 |
template<class T>
|
| 377 |
-
|
| 378 |
template<class T>
|
| 379 |
-
|
| 380 |
template<class T, class U>
|
| 381 |
-
|
| 382 |
template<class T>
|
| 383 |
-
|
| 384 |
template<class T>
|
| 385 |
-
|
| 386 |
template<class T, class... Args>
|
| 387 |
-
|
| 388 |
= is_trivially_constructible<T, Args...>::value;
|
| 389 |
template<class T>
|
| 390 |
-
|
| 391 |
= is_trivially_default_constructible<T>::value;
|
| 392 |
template<class T>
|
| 393 |
-
|
| 394 |
= is_trivially_copy_constructible<T>::value;
|
| 395 |
template<class T>
|
| 396 |
-
|
| 397 |
= is_trivially_move_constructible<T>::value;
|
| 398 |
template<class T, class U>
|
| 399 |
-
|
| 400 |
template<class T>
|
| 401 |
-
|
| 402 |
= is_trivially_copy_assignable<T>::value;
|
| 403 |
template<class T>
|
| 404 |
-
|
| 405 |
= is_trivially_move_assignable<T>::value;
|
| 406 |
template<class T>
|
| 407 |
-
|
| 408 |
template<class T, class... Args>
|
| 409 |
-
|
| 410 |
= is_nothrow_constructible<T, Args...>::value;
|
| 411 |
template<class T>
|
| 412 |
-
|
| 413 |
= is_nothrow_default_constructible<T>::value;
|
| 414 |
template<class T>
|
| 415 |
-
|
| 416 |
= is_nothrow_copy_constructible<T>::value;
|
| 417 |
template<class T>
|
| 418 |
-
|
| 419 |
= is_nothrow_move_constructible<T>::value;
|
| 420 |
template<class T, class U>
|
| 421 |
-
|
| 422 |
template<class T>
|
| 423 |
-
|
| 424 |
template<class T>
|
| 425 |
-
|
| 426 |
template<class T, class U>
|
| 427 |
-
|
| 428 |
template<class T>
|
| 429 |
-
|
| 430 |
template<class T>
|
| 431 |
-
|
| 432 |
template<class T>
|
| 433 |
-
|
| 434 |
template<class T>
|
| 435 |
-
|
|
|
|
|
|
|
| 436 |
= has_unique_object_representations<T>::value;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 437 |
|
| 438 |
// [meta.unary.prop.query], type property queries
|
| 439 |
template<class T>
|
| 440 |
-
|
| 441 |
template<class T>
|
| 442 |
-
|
| 443 |
template<class T, unsigned I = 0>
|
| 444 |
-
|
| 445 |
|
| 446 |
// [meta.rel], type relations
|
| 447 |
template<class T, class U>
|
| 448 |
-
|
| 449 |
template<class Base, class Derived>
|
| 450 |
-
|
| 451 |
template<class From, class To>
|
| 452 |
-
|
| 453 |
template<class From, class To>
|
| 454 |
-
|
| 455 |
template<class T, class U>
|
| 456 |
-
|
| 457 |
template<class Base, class Derived>
|
| 458 |
-
|
| 459 |
= is_pointer_interconvertible_base_of<Base, Derived>::value;
|
| 460 |
template<class Fn, class... ArgTypes>
|
| 461 |
-
|
| 462 |
template<class R, class Fn, class... ArgTypes>
|
| 463 |
-
|
| 464 |
template<class Fn, class... ArgTypes>
|
| 465 |
-
|
| 466 |
template<class R, class Fn, class... ArgTypes>
|
| 467 |
-
|
| 468 |
= is_nothrow_invocable_r<R, Fn, ArgTypes...>::value;
|
| 469 |
|
| 470 |
// [meta.logical], logical operator traits
|
| 471 |
template<class... B>
|
| 472 |
-
|
| 473 |
template<class... B>
|
| 474 |
-
|
| 475 |
template<class B>
|
| 476 |
-
|
| 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>
|
|
@@ -506,12 +576,14 @@ The class template `integral_constant`, alias template `bool_constant`,
|
|
| 506 |
and its associated *typedef-name*s `true_type` and `false_type` are used
|
| 507 |
as base classes to define the interface for various type traits.
|
| 508 |
|
| 509 |
### Unary type traits <a id="meta.unary">[[meta.unary]]</a>
|
| 510 |
|
| 511 |
-
|
| 512 |
-
|
|
|
|
|
|
|
| 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 |
|
|
@@ -549,17 +621,23 @@ 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
|
| 555 |
-
odr-use [[
|
| 556 |
corresponding definition notwithstanding the restrictions of
|
| 557 |
[[declval]].
|
| 558 |
|
| 559 |
-
|
| 560 |
-
`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 561 |
|
| 562 |
[*Example 1*:
|
| 563 |
|
| 564 |
``` cpp
|
| 565 |
is_const_v<const volatile int> // true
|
|
@@ -681,17 +759,14 @@ 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
|
| 692 |
-
odr-use [[
|
| 693 |
corresponding definition notwithstanding the restrictions of
|
| 694 |
[[declval]].
|
| 695 |
|
| 696 |
[*Example 1*:
|
| 697 |
|
|
@@ -722,51 +797,42 @@ implicit conversions to the return type of the function:
|
|
| 722 |
To test() {
|
| 723 |
return declval<From>();
|
| 724 |
}
|
| 725 |
```
|
| 726 |
|
| 727 |
-
[*Note
|
| 728 |
-
types,
|
| 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
|
| 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
|
| 739 |
in the program being ill-formed. — *end note*]
|
| 740 |
|
| 741 |
### Transformations between types <a id="meta.trans">[[meta.trans]]</a>
|
| 742 |
|
| 743 |
-
|
| 744 |
-
to another following some predefined rule.
|
| 745 |
|
| 746 |
-
|
|
|
|
|
|
|
|
|
|
| 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 |
|
| 764 |
-
[*Note 1*: For multidimensional arrays, only the first array dimension
|
| 765 |
-
is removed. For a type “array of `const U`”, the resulting type is
|
| 766 |
-
`const U`. — *end note*]
|
| 767 |
-
|
| 768 |
[*Example 1*:
|
| 769 |
|
| 770 |
``` cpp
|
| 771 |
// the following assertions hold:
|
| 772 |
assert((is_same_v<remove_extent_t<int>, int>));
|
|
@@ -791,30 +857,15 @@ assert((is_same_v<remove_all_extents_t<int[][3]>, int>));
|
|
| 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*:
|
| 797 |
-
|
| 798 |
-
|
| 799 |
-
|
| 800 |
-
|
| 801 |
-
|
| 802 |
-
[*Note 2*:
|
| 803 |
-
|
| 804 |
-
A typical implementation would define `aligned_storage` as:
|
| 805 |
-
|
| 806 |
-
``` cpp
|
| 807 |
-
template<size_t Len, size_t Alignment>
|
| 808 |
-
struct aligned_storage {
|
| 809 |
-
typedef struct {
|
| 810 |
-
alignas(Alignment) unsigned char __data[Len];
|
| 811 |
-
} type;
|
| 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.
|
|
@@ -865,11 +916,11 @@ as follows:
|
|
| 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
|
| 871 |
specialization `common_type<D1, D2>`. — *end note*]
|
| 872 |
- Otherwise, if
|
| 873 |
``` cpp
|
| 874 |
decay_t<decltype(false ? declval<D1>() : declval<D2>())>
|
| 875 |
```
|
|
@@ -893,20 +944,19 @@ Note B: Notwithstanding the provisions of [[meta.type.synop]], and
|
|
| 893 |
pursuant to [[namespace.std]], a program may specialize
|
| 894 |
`common_type<T1, T2>` for types `T1` and `T2` such that
|
| 895 |
`is_same_v<T1, decay_t<T1>>` and `is_same_v<T2, decay_t<T2>>` are each
|
| 896 |
`true`.
|
| 897 |
|
| 898 |
-
[*Note
|
| 899 |
conversions are desired between the template arguments. — *end note*]
|
| 900 |
|
| 901 |
Such a specialization need not have a member named `type`, but if it
|
| 902 |
-
does,
|
| 903 |
-
|
| 904 |
-
|
| 905 |
-
|
| 906 |
-
|
| 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 |
|
|
@@ -914,12 +964,14 @@ follows:
|
|
| 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 |
-
-
|
| 920 |
-
|
|
|
|
|
|
|
| 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
|
|
@@ -936,23 +988,23 @@ follows:
|
|
| 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>
|
| 942 |
-
|
| 943 |
|
| 944 |
-
[*Note
|
| 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,
|
| 950 |
-
|
| 951 |
-
`UQual<U>` is convertible.
|
| 952 |
-
`basic_common_reference<T, U, TQual, UQual>::type` shall
|
| 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 |
|
|
@@ -1088,13 +1140,13 @@ template<class S1, class S2, class M1, class M2>
|
|
| 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
|
| 1094 |
-
`m1` and `m2` point to corresponding members of
|
| 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
|
|
@@ -1129,13 +1181,19 @@ static_assert( is_corresponding_member<C, C>( &C::a, &C::b ) );
|
|
| 1129 |
|
| 1130 |
``` cpp
|
| 1131 |
constexpr bool is_constant_evaluated() noexcept;
|
| 1132 |
```
|
| 1133 |
|
| 1134 |
-
*
|
| 1135 |
-
|
| 1136 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1137 |
|
| 1138 |
[*Example 1*:
|
| 1139 |
|
| 1140 |
``` cpp
|
| 1141 |
constexpr void f(unsigned char *p, int n) {
|
|
@@ -1147,5 +1205,280 @@ constexpr void f(unsigned char *p, int n) {
|
|
| 1147 |
}
|
| 1148 |
```
|
| 1149 |
|
| 1150 |
— *end example*]
|
| 1151 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Metaprogramming library <a id="meta">[[meta]]</a>
|
| 2 |
+
|
| 3 |
+
## General <a id="meta.general">[[meta.general]]</a>
|
| 4 |
+
|
| 5 |
+
This Clause describes metaprogramming facilities. These facilities are
|
| 6 |
+
summarized in [[meta.summary]].
|
| 7 |
+
|
| 8 |
+
**Table: Metaprogramming library summary** <a id="meta.summary">[meta.summary]</a>
|
| 9 |
+
|
| 10 |
+
| Subclause | | Header |
|
| 11 |
+
| --------------- | ------------------- | --------------- |
|
| 12 |
+
| [[intseq]] | Integer sequences | `<utility>` |
|
| 13 |
+
| [[type.traits]] | Type traits | `<type_traits>` |
|
| 14 |
+
| [[ratio]] | Rational arithmetic | `<ratio>` |
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
## Compile-time integer sequences <a id="intseq">[[intseq]]</a>
|
| 18 |
+
|
| 19 |
+
### In general <a id="intseq.general">[[intseq.general]]</a>
|
| 20 |
+
|
| 21 |
+
The library provides a class template that can represent an integer
|
| 22 |
+
sequence. When used as an argument to a function template the template
|
| 23 |
+
parameter pack defining the sequence can be deduced and used in a pack
|
| 24 |
+
expansion.
|
| 25 |
+
|
| 26 |
+
[*Note 1*: The `index_sequence` alias template is provided for the
|
| 27 |
+
common case of an integer sequence of type `size_t`; see also
|
| 28 |
+
[[tuple.apply]]. — *end note*]
|
| 29 |
+
|
| 30 |
+
### Class template `integer_sequence` <a id="intseq.intseq">[[intseq.intseq]]</a>
|
| 31 |
+
|
| 32 |
+
``` cpp
|
| 33 |
+
namespace std {
|
| 34 |
+
template<class T, T... I> struct integer_sequence {
|
| 35 |
+
using value_type = T;
|
| 36 |
+
static constexpr size_t size() noexcept { return sizeof...(I); }
|
| 37 |
+
};
|
| 38 |
+
}
|
| 39 |
+
```
|
| 40 |
+
|
| 41 |
+
*Mandates:* `T` is an integer type.
|
| 42 |
+
|
| 43 |
+
### Alias template `make_integer_sequence` <a id="intseq.make">[[intseq.make]]</a>
|
| 44 |
+
|
| 45 |
+
``` cpp
|
| 46 |
+
template<class T, T N>
|
| 47 |
+
using make_integer_sequence = integer_sequence<T, see below>;
|
| 48 |
+
```
|
| 49 |
+
|
| 50 |
+
*Mandates:* `N` ≥ 0.
|
| 51 |
+
|
| 52 |
+
The alias template `make_integer_sequence` denotes a specialization of
|
| 53 |
+
`integer_sequence` with `N` non-type template arguments. The type
|
| 54 |
+
`make_integer_sequence<T, N>` is an alias for the type
|
| 55 |
+
`integer_sequence<T, 0, 1, ..., N-1>`.
|
| 56 |
+
|
| 57 |
+
[*Note 1*: `make_integer_sequence<int, 0>` is an alias for the type
|
| 58 |
+
`integer_sequence<int>`. — *end note*]
|
| 59 |
+
|
| 60 |
+
## Metaprogramming and type traits <a id="type.traits">[[type.traits]]</a>
|
| 61 |
+
|
| 62 |
+
### General <a id="type.traits.general">[[type.traits.general]]</a>
|
| 63 |
+
|
| 64 |
+
Subclause [[type.traits]] describes components used by C++ programs,
|
| 65 |
+
particularly in templates, to support the widest possible range of
|
| 66 |
+
types, optimize template code usage, detect type related user errors,
|
| 67 |
+
and perform type inference and transformation at compile time. It
|
| 68 |
+
includes type classification traits, type property inspection traits,
|
| 69 |
+
and type transformations. The type classification traits describe a
|
| 70 |
+
complete taxonomy of all possible C++ types, and state where in that
|
| 71 |
+
taxonomy a given type belongs. The type property inspection traits allow
|
| 72 |
+
important characteristics of types or of combinations of types to be
|
| 73 |
+
inspected. The type transformations allow certain properties of types to
|
| 74 |
+
be manipulated.
|
| 75 |
+
|
| 76 |
+
All functions specified in [[type.traits]] are signal-safe
|
| 77 |
[[support.signal]].
|
| 78 |
|
| 79 |
### Requirements <a id="meta.rqmts">[[meta.rqmts]]</a>
|
| 80 |
|
| 81 |
A describes a property of a type. It shall be a class template that
|
|
|
|
| 107 |
help define the modification. It shall define a publicly accessible
|
| 108 |
nested type named `type`, which shall be a synonym for the modified
|
| 109 |
type.
|
| 110 |
|
| 111 |
Unless otherwise specified, the behavior of a program that adds
|
| 112 |
+
specializations for any of the templates specified in [[type.traits]] is
|
| 113 |
+
undefined.
|
| 114 |
|
| 115 |
Unless otherwise specified, an incomplete type may be used to
|
| 116 |
+
instantiate a template specified in [[type.traits]]. The behavior of a
|
| 117 |
program is undefined if:
|
| 118 |
|
| 119 |
+
- an instantiation of a template specified in [[type.traits]] directly
|
| 120 |
+
or indirectly depends on an incompletely-defined object type `T`, and
|
|
|
|
| 121 |
- that instantiation could yield a different result were `T`
|
| 122 |
hypothetically completed.
|
| 123 |
|
| 124 |
### Header `<type_traits>` synopsis <a id="meta.type.synop">[[meta.type.synop]]</a>
|
| 125 |
|
| 126 |
``` cpp
|
| 127 |
+
// all freestanding
|
| 128 |
namespace std {
|
| 129 |
// [meta.help], helper class
|
| 130 |
template<class T, T v> struct integral_constant;
|
| 131 |
|
| 132 |
template<bool B>
|
|
|
|
| 173 |
|
| 174 |
template<class T> struct is_signed;
|
| 175 |
template<class T> struct is_unsigned;
|
| 176 |
template<class T> struct is_bounded_array;
|
| 177 |
template<class T> struct is_unbounded_array;
|
| 178 |
+
template<class T> struct is_scoped_enum;
|
| 179 |
|
| 180 |
template<class T, class... Args> struct is_constructible;
|
| 181 |
template<class T> struct is_default_constructible;
|
| 182 |
template<class T> struct is_copy_constructible;
|
| 183 |
template<class T> struct is_move_constructible;
|
|
|
|
| 213 |
template<class T, class U> struct is_nothrow_swappable_with;
|
| 214 |
template<class T> struct is_nothrow_swappable;
|
| 215 |
|
| 216 |
template<class T> struct is_nothrow_destructible;
|
| 217 |
|
| 218 |
+
template<class T> struct is_implicit_lifetime;
|
| 219 |
+
|
| 220 |
template<class T> struct has_virtual_destructor;
|
| 221 |
|
| 222 |
template<class T> struct has_unique_object_representations;
|
| 223 |
|
| 224 |
+
template<class T, class U> struct reference_constructs_from_temporary;
|
| 225 |
+
template<class T, class U> struct reference_converts_from_temporary;
|
| 226 |
+
|
| 227 |
// [meta.unary.prop.query], type property queries
|
| 228 |
template<class T> struct alignment_of;
|
| 229 |
template<class T> struct rank;
|
| 230 |
template<class T, unsigned I = 0> struct extent;
|
| 231 |
|
|
|
|
| 303 |
template<class T>
|
| 304 |
using add_pointer_t = typename add_pointer<T>::type;
|
| 305 |
|
| 306 |
// [meta.trans.other], other transformations
|
| 307 |
template<class T> struct type_identity;
|
|
|
|
|
|
|
|
|
|
| 308 |
template<class T> struct remove_cvref;
|
| 309 |
template<class T> struct decay;
|
| 310 |
template<bool, class T = void> struct enable_if;
|
| 311 |
template<bool, class T, class F> struct conditional;
|
| 312 |
template<class... T> struct common_type;
|
|
|
|
| 318 |
template<class T> struct unwrap_reference;
|
| 319 |
template<class T> struct unwrap_ref_decay;
|
| 320 |
|
| 321 |
template<class T>
|
| 322 |
using type_identity_t = typename type_identity<T>::type;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 323 |
template<class T>
|
| 324 |
using remove_cvref_t = typename remove_cvref<T>::type;
|
| 325 |
template<class T>
|
| 326 |
using decay_t = typename decay<T>::type;
|
| 327 |
+
template<bool B, class T = void>
|
| 328 |
+
using enable_if_t = typename enable_if<B, T>::type;
|
| 329 |
+
template<bool B, class T, class F>
|
| 330 |
+
using conditional_t = typename conditional<B, T, F>::type;
|
| 331 |
template<class... T>
|
| 332 |
using common_type_t = typename common_type<T...>::type;
|
| 333 |
template<class... T>
|
| 334 |
using common_reference_t = typename common_reference<T...>::type;
|
| 335 |
template<class T>
|
|
|
|
| 348 |
template<class... B> struct disjunction;
|
| 349 |
template<class B> struct negation;
|
| 350 |
|
| 351 |
// [meta.unary.cat], primary type categories
|
| 352 |
template<class T>
|
| 353 |
+
constexpr bool is_void_v = is_void<T>::value;
|
| 354 |
template<class T>
|
| 355 |
+
constexpr bool is_null_pointer_v = is_null_pointer<T>::value;
|
| 356 |
template<class T>
|
| 357 |
+
constexpr bool is_integral_v = is_integral<T>::value;
|
| 358 |
template<class T>
|
| 359 |
+
constexpr bool is_floating_point_v = is_floating_point<T>::value;
|
| 360 |
template<class T>
|
| 361 |
+
constexpr bool is_array_v = is_array<T>::value;
|
| 362 |
template<class T>
|
| 363 |
+
constexpr bool is_pointer_v = is_pointer<T>::value;
|
| 364 |
template<class T>
|
| 365 |
+
constexpr bool is_lvalue_reference_v = is_lvalue_reference<T>::value;
|
| 366 |
template<class T>
|
| 367 |
+
constexpr bool is_rvalue_reference_v = is_rvalue_reference<T>::value;
|
| 368 |
template<class T>
|
| 369 |
+
constexpr bool is_member_object_pointer_v = is_member_object_pointer<T>::value;
|
| 370 |
template<class T>
|
| 371 |
+
constexpr bool is_member_function_pointer_v = is_member_function_pointer<T>::value;
|
| 372 |
template<class T>
|
| 373 |
+
constexpr bool is_enum_v = is_enum<T>::value;
|
| 374 |
template<class T>
|
| 375 |
+
constexpr bool is_union_v = is_union<T>::value;
|
| 376 |
template<class T>
|
| 377 |
+
constexpr bool is_class_v = is_class<T>::value;
|
| 378 |
template<class T>
|
| 379 |
+
constexpr bool is_function_v = is_function<T>::value;
|
| 380 |
|
| 381 |
// [meta.unary.comp], composite type categories
|
| 382 |
template<class T>
|
| 383 |
+
constexpr bool is_reference_v = is_reference<T>::value;
|
| 384 |
template<class T>
|
| 385 |
+
constexpr bool is_arithmetic_v = is_arithmetic<T>::value;
|
| 386 |
template<class T>
|
| 387 |
+
constexpr bool is_fundamental_v = is_fundamental<T>::value;
|
| 388 |
template<class T>
|
| 389 |
+
constexpr bool is_object_v = is_object<T>::value;
|
| 390 |
template<class T>
|
| 391 |
+
constexpr bool is_scalar_v = is_scalar<T>::value;
|
| 392 |
template<class T>
|
| 393 |
+
constexpr bool is_compound_v = is_compound<T>::value;
|
| 394 |
template<class T>
|
| 395 |
+
constexpr bool is_member_pointer_v = is_member_pointer<T>::value;
|
| 396 |
|
| 397 |
// [meta.unary.prop], type properties
|
| 398 |
template<class T>
|
| 399 |
+
constexpr bool is_const_v = is_const<T>::value;
|
| 400 |
template<class T>
|
| 401 |
+
constexpr bool is_volatile_v = is_volatile<T>::value;
|
| 402 |
template<class T>
|
| 403 |
+
constexpr bool is_trivial_v = is_trivial<T>::value;
|
| 404 |
template<class T>
|
| 405 |
+
constexpr bool is_trivially_copyable_v = is_trivially_copyable<T>::value;
|
| 406 |
template<class T>
|
| 407 |
+
constexpr bool is_standard_layout_v = is_standard_layout<T>::value;
|
| 408 |
template<class T>
|
| 409 |
+
constexpr bool is_empty_v = is_empty<T>::value;
|
| 410 |
template<class T>
|
| 411 |
+
constexpr bool is_polymorphic_v = is_polymorphic<T>::value;
|
| 412 |
template<class T>
|
| 413 |
+
constexpr bool is_abstract_v = is_abstract<T>::value;
|
| 414 |
template<class T>
|
| 415 |
+
constexpr bool is_final_v = is_final<T>::value;
|
| 416 |
template<class T>
|
| 417 |
+
constexpr bool is_aggregate_v = is_aggregate<T>::value;
|
| 418 |
template<class T>
|
| 419 |
+
constexpr bool is_signed_v = is_signed<T>::value;
|
| 420 |
template<class T>
|
| 421 |
+
constexpr bool is_unsigned_v = is_unsigned<T>::value;
|
| 422 |
template<class T>
|
| 423 |
+
constexpr bool is_bounded_array_v = is_bounded_array<T>::value;
|
| 424 |
template<class T>
|
| 425 |
+
constexpr bool is_unbounded_array_v = is_unbounded_array<T>::value;
|
| 426 |
+
template<class T>
|
| 427 |
+
constexpr bool is_scoped_enum_v = is_scoped_enum<T>::value;
|
| 428 |
template<class T, class... Args>
|
| 429 |
+
constexpr bool is_constructible_v = is_constructible<T, Args...>::value;
|
| 430 |
template<class T>
|
| 431 |
+
constexpr bool is_default_constructible_v = is_default_constructible<T>::value;
|
| 432 |
template<class T>
|
| 433 |
+
constexpr bool is_copy_constructible_v = is_copy_constructible<T>::value;
|
| 434 |
template<class T>
|
| 435 |
+
constexpr bool is_move_constructible_v = is_move_constructible<T>::value;
|
| 436 |
template<class T, class U>
|
| 437 |
+
constexpr bool is_assignable_v = is_assignable<T, U>::value;
|
| 438 |
template<class T>
|
| 439 |
+
constexpr bool is_copy_assignable_v = is_copy_assignable<T>::value;
|
| 440 |
template<class T>
|
| 441 |
+
constexpr bool is_move_assignable_v = is_move_assignable<T>::value;
|
| 442 |
template<class T, class U>
|
| 443 |
+
constexpr bool is_swappable_with_v = is_swappable_with<T, U>::value;
|
| 444 |
template<class T>
|
| 445 |
+
constexpr bool is_swappable_v = is_swappable<T>::value;
|
| 446 |
template<class T>
|
| 447 |
+
constexpr bool is_destructible_v = is_destructible<T>::value;
|
| 448 |
template<class T, class... Args>
|
| 449 |
+
constexpr bool is_trivially_constructible_v
|
| 450 |
= is_trivially_constructible<T, Args...>::value;
|
| 451 |
template<class T>
|
| 452 |
+
constexpr bool is_trivially_default_constructible_v
|
| 453 |
= is_trivially_default_constructible<T>::value;
|
| 454 |
template<class T>
|
| 455 |
+
constexpr bool is_trivially_copy_constructible_v
|
| 456 |
= is_trivially_copy_constructible<T>::value;
|
| 457 |
template<class T>
|
| 458 |
+
constexpr bool is_trivially_move_constructible_v
|
| 459 |
= is_trivially_move_constructible<T>::value;
|
| 460 |
template<class T, class U>
|
| 461 |
+
constexpr bool is_trivially_assignable_v = is_trivially_assignable<T, U>::value;
|
| 462 |
template<class T>
|
| 463 |
+
constexpr bool is_trivially_copy_assignable_v
|
| 464 |
= is_trivially_copy_assignable<T>::value;
|
| 465 |
template<class T>
|
| 466 |
+
constexpr bool is_trivially_move_assignable_v
|
| 467 |
= is_trivially_move_assignable<T>::value;
|
| 468 |
template<class T>
|
| 469 |
+
constexpr bool is_trivially_destructible_v = is_trivially_destructible<T>::value;
|
| 470 |
template<class T, class... Args>
|
| 471 |
+
constexpr bool is_nothrow_constructible_v
|
| 472 |
= is_nothrow_constructible<T, Args...>::value;
|
| 473 |
template<class T>
|
| 474 |
+
constexpr bool is_nothrow_default_constructible_v
|
| 475 |
= is_nothrow_default_constructible<T>::value;
|
| 476 |
template<class T>
|
| 477 |
+
constexpr bool is_nothrow_copy_constructible_v
|
| 478 |
= is_nothrow_copy_constructible<T>::value;
|
| 479 |
template<class T>
|
| 480 |
+
constexpr bool is_nothrow_move_constructible_v
|
| 481 |
= is_nothrow_move_constructible<T>::value;
|
| 482 |
template<class T, class U>
|
| 483 |
+
constexpr bool is_nothrow_assignable_v = is_nothrow_assignable<T, U>::value;
|
| 484 |
template<class T>
|
| 485 |
+
constexpr bool is_nothrow_copy_assignable_v = is_nothrow_copy_assignable<T>::value;
|
| 486 |
template<class T>
|
| 487 |
+
constexpr bool is_nothrow_move_assignable_v = is_nothrow_move_assignable<T>::value;
|
| 488 |
template<class T, class U>
|
| 489 |
+
constexpr bool is_nothrow_swappable_with_v = is_nothrow_swappable_with<T, U>::value;
|
| 490 |
template<class T>
|
| 491 |
+
constexpr bool is_nothrow_swappable_v = is_nothrow_swappable<T>::value;
|
| 492 |
template<class T>
|
| 493 |
+
constexpr bool is_nothrow_destructible_v = is_nothrow_destructible<T>::value;
|
| 494 |
template<class T>
|
| 495 |
+
constexpr bool is_implicit_lifetime_v = is_implicit_lifetime<T>::value;
|
| 496 |
template<class T>
|
| 497 |
+
constexpr bool has_virtual_destructor_v = has_virtual_destructor<T>::value;
|
| 498 |
+
template<class T>
|
| 499 |
+
constexpr bool has_unique_object_representations_v
|
| 500 |
= has_unique_object_representations<T>::value;
|
| 501 |
+
template<class T, class U>
|
| 502 |
+
constexpr bool reference_constructs_from_temporary_v
|
| 503 |
+
= reference_constructs_from_temporary<T, U>::value;
|
| 504 |
+
template<class T, class U>
|
| 505 |
+
constexpr bool reference_converts_from_temporary_v
|
| 506 |
+
= reference_converts_from_temporary<T, U>::value;
|
| 507 |
|
| 508 |
// [meta.unary.prop.query], type property queries
|
| 509 |
template<class T>
|
| 510 |
+
constexpr size_t alignment_of_v = alignment_of<T>::value;
|
| 511 |
template<class T>
|
| 512 |
+
constexpr size_t rank_v = rank<T>::value;
|
| 513 |
template<class T, unsigned I = 0>
|
| 514 |
+
constexpr size_t extent_v = extent<T, I>::value;
|
| 515 |
|
| 516 |
// [meta.rel], type relations
|
| 517 |
template<class T, class U>
|
| 518 |
+
constexpr bool is_same_v = is_same<T, U>::value;
|
| 519 |
template<class Base, class Derived>
|
| 520 |
+
constexpr bool is_base_of_v = is_base_of<Base, Derived>::value;
|
| 521 |
template<class From, class To>
|
| 522 |
+
constexpr bool is_convertible_v = is_convertible<From, To>::value;
|
| 523 |
template<class From, class To>
|
| 524 |
+
constexpr bool is_nothrow_convertible_v = is_nothrow_convertible<From, To>::value;
|
| 525 |
template<class T, class U>
|
| 526 |
+
constexpr bool is_layout_compatible_v = is_layout_compatible<T, U>::value;
|
| 527 |
template<class Base, class Derived>
|
| 528 |
+
constexpr bool is_pointer_interconvertible_base_of_v
|
| 529 |
= is_pointer_interconvertible_base_of<Base, Derived>::value;
|
| 530 |
template<class Fn, class... ArgTypes>
|
| 531 |
+
constexpr bool is_invocable_v = is_invocable<Fn, ArgTypes...>::value;
|
| 532 |
template<class R, class Fn, class... ArgTypes>
|
| 533 |
+
constexpr bool is_invocable_r_v = is_invocable_r<R, Fn, ArgTypes...>::value;
|
| 534 |
template<class Fn, class... ArgTypes>
|
| 535 |
+
constexpr bool is_nothrow_invocable_v = is_nothrow_invocable<Fn, ArgTypes...>::value;
|
| 536 |
template<class R, class Fn, class... ArgTypes>
|
| 537 |
+
constexpr bool is_nothrow_invocable_r_v
|
| 538 |
= is_nothrow_invocable_r<R, Fn, ArgTypes...>::value;
|
| 539 |
|
| 540 |
// [meta.logical], logical operator traits
|
| 541 |
template<class... B>
|
| 542 |
+
constexpr bool conjunction_v = conjunction<B...>::value;
|
| 543 |
template<class... B>
|
| 544 |
+
constexpr bool disjunction_v = disjunction<B...>::value;
|
| 545 |
template<class B>
|
| 546 |
+
constexpr bool negation_v = negation<B>::value;
|
| 547 |
|
| 548 |
// [meta.member], member relationships
|
| 549 |
template<class S, class M>
|
| 550 |
constexpr bool is_pointer_interconvertible_with_class(M S::*m) noexcept;
|
| 551 |
template<class S1, class S2, class M1, class M2>
|
|
|
|
| 576 |
and its associated *typedef-name*s `true_type` and `false_type` are used
|
| 577 |
as base classes to define the interface for various type traits.
|
| 578 |
|
| 579 |
### Unary type traits <a id="meta.unary">[[meta.unary]]</a>
|
| 580 |
|
| 581 |
+
#### General <a id="meta.unary.general">[[meta.unary.general]]</a>
|
| 582 |
+
|
| 583 |
+
Subclause [[meta.unary]] contains templates that may be used to query
|
| 584 |
+
the properties of a type at compile time.
|
| 585 |
|
| 586 |
Each of these templates shall be a *Cpp17UnaryTypeTrait* [[meta.rqmts]]
|
| 587 |
with a base characteristic of `true_type` if the corresponding condition
|
| 588 |
is `true`, otherwise `false_type`.
|
| 589 |
|
|
|
|
| 621 |
template argument if and only if the semantics of `X` require that the
|
| 622 |
argument is a complete type.
|
| 623 |
|
| 624 |
For the purpose of defining the templates in this subclause, a function
|
| 625 |
call expression `declval<T>()` for any type `T` is considered to be a
|
| 626 |
+
trivial [[term.trivial.type]], [[special]] function call that is not an
|
| 627 |
+
odr-use [[term.odr.use]] of `declval` in the context of the
|
| 628 |
corresponding definition notwithstanding the restrictions of
|
| 629 |
[[declval]].
|
| 630 |
|
| 631 |
+
For the purpose of defining the templates in this subclause, let
|
| 632 |
+
`VAL<T>` for some type `T` be an expression defined as follows:
|
| 633 |
+
|
| 634 |
+
- If `T` is a reference or function type, `VAL<T>` is an expression with
|
| 635 |
+
the same type and value category as `declval<T>()`.
|
| 636 |
+
- Otherwise, `VAL<T>` is a prvalue that initially has type `T`.
|
| 637 |
+
\[*Note 1*: If `T` is cv-qualified, the cv-qualification is subject to
|
| 638 |
+
adjustment [[expr.type]]. — *end note*]
|
| 639 |
|
| 640 |
[*Example 1*:
|
| 641 |
|
| 642 |
``` cpp
|
| 643 |
is_const_v<const volatile int> // true
|
|
|
|
| 759 |
|
| 760 |
Each of these templates shall be a *Cpp17BinaryTypeTrait* [[meta.rqmts]]
|
| 761 |
with a base characteristic of `true_type` if the corresponding condition
|
| 762 |
is true, otherwise `false_type`.
|
| 763 |
|
|
|
|
|
|
|
|
|
|
| 764 |
For the purpose of defining the templates in this subclause, a function
|
| 765 |
call expression `declval<T>()` for any type `T` is considered to be a
|
| 766 |
+
trivial [[term.trivial.type]], [[special]] function call that is not an
|
| 767 |
+
odr-use [[term.odr.use]] of `declval` in the context of the
|
| 768 |
corresponding definition notwithstanding the restrictions of
|
| 769 |
[[declval]].
|
| 770 |
|
| 771 |
[*Example 1*:
|
| 772 |
|
|
|
|
| 797 |
To test() {
|
| 798 |
return declval<From>();
|
| 799 |
}
|
| 800 |
```
|
| 801 |
|
| 802 |
+
[*Note 1*: This requirement gives well-defined results for reference
|
| 803 |
+
types, array types, function types, and cv `void`. — *end note*]
|
| 804 |
|
| 805 |
Access checking is performed in a context unrelated to `To` and `From`.
|
| 806 |
Only the validity of the immediate context of the *expression* of the
|
| 807 |
`return` statement [[stmt.return]] (including initialization of the
|
| 808 |
returned object or reference) is considered.
|
| 809 |
|
| 810 |
+
[*Note 2*: The initialization can result in side effects such as the
|
| 811 |
instantiation of class template specializations and function template
|
| 812 |
specializations, the generation of implicitly-defined functions, and so
|
| 813 |
on. Such side effects are not in the “immediate context” and can result
|
| 814 |
in the program being ill-formed. — *end note*]
|
| 815 |
|
| 816 |
### Transformations between types <a id="meta.trans">[[meta.trans]]</a>
|
| 817 |
|
| 818 |
+
#### General <a id="meta.trans.general">[[meta.trans.general]]</a>
|
|
|
|
| 819 |
|
| 820 |
+
Subclause [[meta.trans]] contains templates that may be used to
|
| 821 |
+
transform one type to another following some predefined rule.
|
| 822 |
+
|
| 823 |
+
Each of the templates in [[meta.trans]] shall be a
|
| 824 |
*Cpp17TransformationTrait* [[meta.rqmts]].
|
| 825 |
|
| 826 |
#### Const-volatile modifications <a id="meta.trans.cv">[[meta.trans.cv]]</a>
|
| 827 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 828 |
#### Reference modifications <a id="meta.trans.ref">[[meta.trans.ref]]</a>
|
| 829 |
|
|
|
|
|
|
|
|
|
|
| 830 |
#### Sign modifications <a id="meta.trans.sign">[[meta.trans.sign]]</a>
|
| 831 |
|
| 832 |
#### Array modifications <a id="meta.trans.arr">[[meta.trans.arr]]</a>
|
| 833 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 834 |
[*Example 1*:
|
| 835 |
|
| 836 |
``` cpp
|
| 837 |
// the following assertions hold:
|
| 838 |
assert((is_same_v<remove_extent_t<int>, int>));
|
|
|
|
| 857 |
|
| 858 |
#### Pointer modifications <a id="meta.trans.ptr">[[meta.trans.ptr]]</a>
|
| 859 |
|
| 860 |
#### Other transformations <a id="meta.trans.other">[[meta.trans.other]]</a>
|
| 861 |
|
| 862 |
+
[*Note 1*: The compilation of the expression can result in side effects
|
| 863 |
+
such as the instantiation of class template specializations and function
|
| 864 |
+
template specializations, the generation of implicitly-defined
|
| 865 |
+
functions, and so on. Such side effects are not in the “immediate
|
| 866 |
+
context” and can result in the program being ill-formed. — *end note*]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 867 |
|
| 868 |
In addition to being available via inclusion of the `<type_traits>`
|
| 869 |
header, the templates `unwrap_reference`, `unwrap_ref_decay`,
|
| 870 |
`unwrap_reference_t`, and `unwrap_ref_decay_t` are available when the
|
| 871 |
header `<functional>` [[functional.syn]] is included.
|
|
|
|
| 916 |
`T` be denoted by `T1` and `T2`, respectively, and let `D1` and `D2`
|
| 917 |
denote the same types as `decay_t<T1>` and `decay_t<T2>`,
|
| 918 |
respectively.
|
| 919 |
- If `is_same_v<T1, D1>` is `false` or `is_same_v<T2, D2>` is `false`,
|
| 920 |
let `C` denote the same type, if any, as `common_type_t<D1, D2>`.
|
| 921 |
+
- \[*Note 2*: None of the following will apply if there is a
|
| 922 |
specialization `common_type<D1, D2>`. — *end note*]
|
| 923 |
- Otherwise, if
|
| 924 |
``` cpp
|
| 925 |
decay_t<decltype(false ? declval<D1>() : declval<D2>())>
|
| 926 |
```
|
|
|
|
| 944 |
pursuant to [[namespace.std]], a program may specialize
|
| 945 |
`common_type<T1, T2>` for types `T1` and `T2` such that
|
| 946 |
`is_same_v<T1, decay_t<T1>>` and `is_same_v<T2, decay_t<T2>>` are each
|
| 947 |
`true`.
|
| 948 |
|
| 949 |
+
[*Note 3*: Such specializations are needed when only explicit
|
| 950 |
conversions are desired between the template arguments. — *end note*]
|
| 951 |
|
| 952 |
Such a specialization need not have a member named `type`, but if it
|
| 953 |
+
does, the *qualified-id* `common_type<T1, T2>::type` shall denote a
|
| 954 |
+
cv-unqualified non-reference type to which each of the types `T1` and
|
| 955 |
+
`T2` is explicitly convertible. Moreover, `common_type_t<T1, T2>` shall
|
| 956 |
+
denote the same type, if any, as does `common_type_t<T2, T1>`. No
|
| 957 |
+
diagnostic is required for a violation of this Note’s rules.
|
|
|
|
| 958 |
|
| 959 |
Note C: For the `common_reference` trait applied to a parameter pack `T`
|
| 960 |
of types, the member `type` shall be either defined or not present as
|
| 961 |
follows:
|
| 962 |
|
|
|
|
| 964 |
- Otherwise, if `sizeof...(T)` is one, let `T0` denote the sole type in
|
| 965 |
the pack `T`. The member typedef `type` shall denote the same type as
|
| 966 |
`T0`.
|
| 967 |
- Otherwise, if `sizeof...(T)` is two, let `T1` and `T2` denote the two
|
| 968 |
types in the pack `T`. Then
|
| 969 |
+
- Let `R` be `COMMON-REF(T1, T2)`. If `T1` and `T2` are reference
|
| 970 |
+
types, `R` is well-formed, and
|
| 971 |
+
`is_convertible_v<add_pointer_t<T1>, add_pointer_t<R>> && is_convertible_v<add_poin{}ter_t<T2>, add_pointer_t<R>>`
|
| 972 |
+
is `true`, then the member typedef `type` denotes `R`.
|
| 973 |
- Otherwise, if
|
| 974 |
`basic_common_reference<remove_cvref_t<T1>, remove_cvref_t<T2>,
|
| 975 |
{}XREF({}T1), XREF(T2)>::type` is well-formed, then the member
|
| 976 |
typedef `type` denotes that type.
|
| 977 |
- Otherwise, if `COND-RES(T1, T2)` is well-formed, then the member
|
|
|
|
| 988 |
- Otherwise, there shall be no member `type`.
|
| 989 |
|
| 990 |
Note D: Notwithstanding the provisions of [[meta.type.synop]], and
|
| 991 |
pursuant to [[namespace.std]], a program may partially specialize
|
| 992 |
`basic_common_reference<T, U, TQual, UQual>` for types `T` and `U` such
|
| 993 |
+
that `is_same_v<T, decay_t<T>>` and `is_same_v<U, decay_t<U>>` are each
|
| 994 |
+
`true`.
|
| 995 |
|
| 996 |
+
[*Note 4*: Such specializations can be used to influence the result of
|
| 997 |
`common_reference`, and are needed when only explicit conversions are
|
| 998 |
desired between the template arguments. — *end note*]
|
| 999 |
|
| 1000 |
Such a specialization need not have a member named `type`, but if it
|
| 1001 |
+
does, the *qualified-id*
|
| 1002 |
+
`basic_common_reference<T, U, TQual, UQual>::type` shall denote a type
|
| 1003 |
+
to which each of the types `TQual<T>` and `UQual<U>` is convertible.
|
| 1004 |
+
Moreover, `basic_common_reference<T, U, TQual, UQual>::type` shall
|
| 1005 |
+
denote the same type, if any, as does
|
| 1006 |
`basic_common_reference<U, T, UQual, TQual>::type`. No diagnostic is
|
| 1007 |
required for a violation of these rules.
|
| 1008 |
|
| 1009 |
[*Example 2*:
|
| 1010 |
|
|
|
|
| 1140 |
```
|
| 1141 |
|
| 1142 |
*Mandates:* `S1` and `S2` are complete types.
|
| 1143 |
|
| 1144 |
*Returns:* `true` if and only if `S1` and `S2` are standard-layout
|
| 1145 |
+
struct [[class.prop]] types, `M1` and `M2` are object types, `m1` and
|
| 1146 |
+
`m2` are not null, and `m1` and `m2` point to corresponding members of
|
| 1147 |
+
the common initial sequence [[class.mem]] of `S1` and `S2`.
|
| 1148 |
|
| 1149 |
[*Note 1*:
|
| 1150 |
|
| 1151 |
The type of a pointer-to-member expression `&C::b` is not always a
|
| 1152 |
pointer to member of `C`, leading to potentially surprising results when
|
|
|
|
| 1181 |
|
| 1182 |
``` cpp
|
| 1183 |
constexpr bool is_constant_evaluated() noexcept;
|
| 1184 |
```
|
| 1185 |
|
| 1186 |
+
*Effects:* Equivalent to:
|
| 1187 |
+
|
| 1188 |
+
``` cpp
|
| 1189 |
+
if consteval {
|
| 1190 |
+
return true;
|
| 1191 |
+
} else {
|
| 1192 |
+
return false;
|
| 1193 |
+
}
|
| 1194 |
+
```
|
| 1195 |
|
| 1196 |
[*Example 1*:
|
| 1197 |
|
| 1198 |
``` cpp
|
| 1199 |
constexpr void f(unsigned char *p, int n) {
|
|
|
|
| 1205 |
}
|
| 1206 |
```
|
| 1207 |
|
| 1208 |
— *end example*]
|
| 1209 |
|
| 1210 |
+
## Compile-time rational arithmetic <a id="ratio">[[ratio]]</a>
|
| 1211 |
+
|
| 1212 |
+
### In general <a id="ratio.general">[[ratio.general]]</a>
|
| 1213 |
+
|
| 1214 |
+
Subclause [[ratio]] describes the ratio library. It provides a class
|
| 1215 |
+
template `ratio` which exactly represents any finite rational number
|
| 1216 |
+
with a numerator and denominator representable by compile-time constants
|
| 1217 |
+
of type `intmax_t`.
|
| 1218 |
+
|
| 1219 |
+
Throughout subclause [[ratio]], the names of template parameters are
|
| 1220 |
+
used to express type requirements. If a template parameter is named `R1`
|
| 1221 |
+
or `R2`, and the template argument is not a specialization of the
|
| 1222 |
+
`ratio` template, the program is ill-formed.
|
| 1223 |
+
|
| 1224 |
+
### Header `<ratio>` synopsis <a id="ratio.syn">[[ratio.syn]]</a>
|
| 1225 |
+
|
| 1226 |
+
``` cpp
|
| 1227 |
+
// all freestanding
|
| 1228 |
+
namespace std {
|
| 1229 |
+
// [ratio.ratio], class template ratio
|
| 1230 |
+
template<intmax_t N, intmax_t D = 1> class ratio;
|
| 1231 |
+
|
| 1232 |
+
// [ratio.arithmetic], ratio arithmetic
|
| 1233 |
+
template<class R1, class R2> using ratio_add = see below;
|
| 1234 |
+
template<class R1, class R2> using ratio_subtract = see below;
|
| 1235 |
+
template<class R1, class R2> using ratio_multiply = see below;
|
| 1236 |
+
template<class R1, class R2> using ratio_divide = see below;
|
| 1237 |
+
|
| 1238 |
+
// [ratio.comparison], ratio comparison
|
| 1239 |
+
template<class R1, class R2> struct ratio_equal;
|
| 1240 |
+
template<class R1, class R2> struct ratio_not_equal;
|
| 1241 |
+
template<class R1, class R2> struct ratio_less;
|
| 1242 |
+
template<class R1, class R2> struct ratio_less_equal;
|
| 1243 |
+
template<class R1, class R2> struct ratio_greater;
|
| 1244 |
+
template<class R1, class R2> struct ratio_greater_equal;
|
| 1245 |
+
|
| 1246 |
+
template<class R1, class R2>
|
| 1247 |
+
constexpr bool ratio_equal_v = ratio_equal<R1, R2>::value;
|
| 1248 |
+
template<class R1, class R2>
|
| 1249 |
+
constexpr bool ratio_not_equal_v = ratio_not_equal<R1, R2>::value;
|
| 1250 |
+
template<class R1, class R2>
|
| 1251 |
+
constexpr bool ratio_less_v = ratio_less<R1, R2>::value;
|
| 1252 |
+
template<class R1, class R2>
|
| 1253 |
+
constexpr bool ratio_less_equal_v = ratio_less_equal<R1, R2>::value;
|
| 1254 |
+
template<class R1, class R2>
|
| 1255 |
+
constexpr bool ratio_greater_v = ratio_greater<R1, R2>::value;
|
| 1256 |
+
template<class R1, class R2>
|
| 1257 |
+
constexpr bool ratio_greater_equal_v = ratio_greater_equal<R1, R2>::value;
|
| 1258 |
+
|
| 1259 |
+
// [ratio.si], convenience SI typedefs
|
| 1260 |
+
using yocto = ratio<1, 1'000'000'000'000'000'000'000'000>; // see below
|
| 1261 |
+
using zepto = ratio<1, 1'000'000'000'000'000'000'000>; // see below
|
| 1262 |
+
using atto = ratio<1, 1'000'000'000'000'000'000>;
|
| 1263 |
+
using femto = ratio<1, 1'000'000'000'000'000>;
|
| 1264 |
+
using pico = ratio<1, 1'000'000'000'000>;
|
| 1265 |
+
using nano = ratio<1, 1'000'000'000>;
|
| 1266 |
+
using micro = ratio<1, 1'000'000>;
|
| 1267 |
+
using milli = ratio<1, 1'000>;
|
| 1268 |
+
using centi = ratio<1, 100>;
|
| 1269 |
+
using deci = ratio<1, 10>;
|
| 1270 |
+
using deca = ratio< 10, 1>;
|
| 1271 |
+
using hecto = ratio< 100, 1>;
|
| 1272 |
+
using kilo = ratio< 1'000, 1>;
|
| 1273 |
+
using mega = ratio< 1'000'000, 1>;
|
| 1274 |
+
using giga = ratio< 1'000'000'000, 1>;
|
| 1275 |
+
using tera = ratio< 1'000'000'000'000, 1>;
|
| 1276 |
+
using peta = ratio< 1'000'000'000'000'000, 1>;
|
| 1277 |
+
using exa = ratio< 1'000'000'000'000'000'000, 1>;
|
| 1278 |
+
using zetta = ratio< 1'000'000'000'000'000'000'000, 1>; // see below
|
| 1279 |
+
using yotta = ratio<1'000'000'000'000'000'000'000'000, 1>; // see below
|
| 1280 |
+
}
|
| 1281 |
+
```
|
| 1282 |
+
|
| 1283 |
+
### Class template `ratio` <a id="ratio.ratio">[[ratio.ratio]]</a>
|
| 1284 |
+
|
| 1285 |
+
``` cpp
|
| 1286 |
+
namespace std {
|
| 1287 |
+
template<intmax_t N, intmax_t D = 1> class ratio {
|
| 1288 |
+
public:
|
| 1289 |
+
static constexpr intmax_t num;
|
| 1290 |
+
static constexpr intmax_t den;
|
| 1291 |
+
using type = ratio<num, den>;
|
| 1292 |
+
};
|
| 1293 |
+
}
|
| 1294 |
+
```
|
| 1295 |
+
|
| 1296 |
+
If the template argument `D` is zero or the absolute values of either of
|
| 1297 |
+
the template arguments `N` and `D` is not representable by type
|
| 1298 |
+
`intmax_t`, the program is ill-formed.
|
| 1299 |
+
|
| 1300 |
+
[*Note 1*: These rules ensure that infinite ratios are avoided and that
|
| 1301 |
+
for any negative input, there exists a representable value of its
|
| 1302 |
+
absolute value which is positive. This excludes the most negative
|
| 1303 |
+
value. — *end note*]
|
| 1304 |
+
|
| 1305 |
+
The static data members `num` and `den` shall have the following values,
|
| 1306 |
+
where `gcd` represents the greatest common divisor of the absolute
|
| 1307 |
+
values of `N` and `D`:
|
| 1308 |
+
|
| 1309 |
+
- `num` shall have the value
|
| 1310 |
+
`\operatorname{sgn}(N) * \operatorname{sgn}(D) * abs(N) / gcd`.
|
| 1311 |
+
- `den` shall have the value `abs(D) / gcd`.
|
| 1312 |
+
|
| 1313 |
+
### Arithmetic on `ratio`s <a id="ratio.arithmetic">[[ratio.arithmetic]]</a>
|
| 1314 |
+
|
| 1315 |
+
Each of the alias templates `ratio_add`, `ratio_subtract`,
|
| 1316 |
+
`ratio_multiply`, and `ratio_divide` denotes the result of an arithmetic
|
| 1317 |
+
computation on two `ratio`s `R1` and `R2`. With `X` and `Y` computed (in
|
| 1318 |
+
the absence of arithmetic overflow) as specified by
|
| 1319 |
+
[[ratio.arithmetic]], each alias denotes a `ratio<U, V>` such that `U`
|
| 1320 |
+
is the same as `ratio<X, Y>::num` and `V` is the same as
|
| 1321 |
+
`ratio<X, Y>::den`.
|
| 1322 |
+
|
| 1323 |
+
If it is not possible to represent `U` or `V` with `intmax_t`, the
|
| 1324 |
+
program is ill-formed. Otherwise, an implementation should yield correct
|
| 1325 |
+
values of `U` and `V`. If it is not possible to represent `X` or `Y`
|
| 1326 |
+
with `intmax_t`, the program is ill-formed unless the implementation
|
| 1327 |
+
yields correct values of `U` and `V`.
|
| 1328 |
+
|
| 1329 |
+
**Table: Expressions used to perform ratio arithmetic** <a id="ratio.arithmetic">[ratio.arithmetic]</a>
|
| 1330 |
+
|
| 1331 |
+
| Type | Value of `X` | Value of `Y` |
|
| 1332 |
+
| ------------------------ | --------------------- | ------------------- |
|
| 1333 |
+
| `ratio_add<R1, R2>` | `R1::num * R2::den +` | `R1::den * R2::den` |
|
| 1334 |
+
| | `R2::num * R1::den` | |
|
| 1335 |
+
| `ratio_subtract<R1, R2>` | `R1::num * R2::den -` | `R1::den * R2::den` |
|
| 1336 |
+
| | `R2::num * R1::den` | |
|
| 1337 |
+
| `ratio_multiply<R1, R2>` | `R1::num * R2::num` | `R1::den * R2::den` |
|
| 1338 |
+
| `ratio_divide<R1, R2>` | `R1::num * R2::den` | `R1::den * R2::num` |
|
| 1339 |
+
|
| 1340 |
+
|
| 1341 |
+
[*Example 1*:
|
| 1342 |
+
|
| 1343 |
+
``` cpp
|
| 1344 |
+
static_assert(ratio_add<ratio<1, 3>, ratio<1, 6>>::num == 1, "1/3+1/6 == 1/2");
|
| 1345 |
+
static_assert(ratio_add<ratio<1, 3>, ratio<1, 6>>::den == 2, "1/3+1/6 == 1/2");
|
| 1346 |
+
static_assert(ratio_multiply<ratio<1, 3>, ratio<3, 2>>::num == 1, "1/3*3/2 == 1/2");
|
| 1347 |
+
static_assert(ratio_multiply<ratio<1, 3>, ratio<3, 2>>::den == 2, "1/3*3/2 == 1/2");
|
| 1348 |
+
|
| 1349 |
+
// The following cases may cause the program to be ill-formed under some implementations
|
| 1350 |
+
static_assert(ratio_add<ratio<1, INT_MAX>, ratio<1, INT_MAX>>::num == 2,
|
| 1351 |
+
"1/MAX+1/MAX == 2/MAX");
|
| 1352 |
+
static_assert(ratio_add<ratio<1, INT_MAX>, ratio<1, INT_MAX>>::den == INT_MAX,
|
| 1353 |
+
"1/MAX+1/MAX == 2/MAX");
|
| 1354 |
+
static_assert(ratio_multiply<ratio<1, INT_MAX>, ratio<INT_MAX, 2>>::num == 1,
|
| 1355 |
+
"1/MAX * MAX/2 == 1/2");
|
| 1356 |
+
static_assert(ratio_multiply<ratio<1, INT_MAX>, ratio<INT_MAX, 2>>::den == 2,
|
| 1357 |
+
"1/MAX * MAX/2 == 1/2");
|
| 1358 |
+
```
|
| 1359 |
+
|
| 1360 |
+
— *end example*]
|
| 1361 |
+
|
| 1362 |
+
### Comparison of `ratio`s <a id="ratio.comparison">[[ratio.comparison]]</a>
|
| 1363 |
+
|
| 1364 |
+
``` cpp
|
| 1365 |
+
template<class R1, class R2>
|
| 1366 |
+
struct ratio_equal : bool_constant<R1::num == R2::num && R1::den == R2::den> { };
|
| 1367 |
+
```
|
| 1368 |
+
|
| 1369 |
+
``` cpp
|
| 1370 |
+
template<class R1, class R2>
|
| 1371 |
+
struct ratio_not_equal : bool_constant<!ratio_equal_v<R1, R2>> { };
|
| 1372 |
+
```
|
| 1373 |
+
|
| 1374 |
+
``` cpp
|
| 1375 |
+
template<class R1, class R2>
|
| 1376 |
+
struct ratio_less : bool_constant<see below> { };
|
| 1377 |
+
```
|
| 1378 |
+
|
| 1379 |
+
If `R1::num` × `R2::den` is less than `R2::num` × `R1::den`,
|
| 1380 |
+
`ratio_less<R1, R2>` shall be derived from `bool_constant<true>`;
|
| 1381 |
+
otherwise it shall be derived from `bool_constant<false>`.
|
| 1382 |
+
Implementations may use other algorithms to compute this relationship to
|
| 1383 |
+
avoid overflow. If overflow occurs, the program is ill-formed.
|
| 1384 |
+
|
| 1385 |
+
``` cpp
|
| 1386 |
+
template<class R1, class R2>
|
| 1387 |
+
struct ratio_less_equal : bool_constant<!ratio_less_v<R2, R1>> { };
|
| 1388 |
+
```
|
| 1389 |
+
|
| 1390 |
+
``` cpp
|
| 1391 |
+
template<class R1, class R2>
|
| 1392 |
+
struct ratio_greater : bool_constant<ratio_less_v<R2, R1>> { };
|
| 1393 |
+
```
|
| 1394 |
+
|
| 1395 |
+
``` cpp
|
| 1396 |
+
template<class R1, class R2>
|
| 1397 |
+
struct ratio_greater_equal : bool_constant<!ratio_less_v<R1, R2>> { };
|
| 1398 |
+
```
|
| 1399 |
+
|
| 1400 |
+
### SI types for `ratio` <a id="ratio.si">[[ratio.si]]</a>
|
| 1401 |
+
|
| 1402 |
+
For each of the *typedef-name*s `yocto`, `zepto`, `zetta`, and `yotta`,
|
| 1403 |
+
if both of the constants used in its specification are representable by
|
| 1404 |
+
`intmax_t`, the typedef is defined; if either of the constants is not
|
| 1405 |
+
representable by `intmax_t`, the typedef is not defined.
|
| 1406 |
+
|
| 1407 |
+
<!-- Link reference definitions -->
|
| 1408 |
+
[array]: containers.md#array
|
| 1409 |
+
[basic.compound]: basic.md#basic.compound
|
| 1410 |
+
[basic.fundamental]: basic.md#basic.fundamental
|
| 1411 |
+
[basic.type.qualifier]: basic.md#basic.type.qualifier
|
| 1412 |
+
[basic.types]: basic.md#basic.types
|
| 1413 |
+
[basic.types.general]: basic.md#basic.types.general
|
| 1414 |
+
[class.abstract]: class.md#class.abstract
|
| 1415 |
+
[class.derived]: class.md#class.derived
|
| 1416 |
+
[class.dtor]: class.md#class.dtor
|
| 1417 |
+
[class.mem]: class.md#class.mem
|
| 1418 |
+
[class.pre]: class.md#class.pre
|
| 1419 |
+
[class.prop]: class.md#class.prop
|
| 1420 |
+
[class.temporary]: basic.md#class.temporary
|
| 1421 |
+
[class.virtual]: class.md#class.virtual
|
| 1422 |
+
[conv.rank]: basic.md#conv.rank
|
| 1423 |
+
[dcl.array]: dcl.md#dcl.array
|
| 1424 |
+
[dcl.enum]: dcl.md#dcl.enum
|
| 1425 |
+
[dcl.init.aggr]: dcl.md#dcl.init.aggr
|
| 1426 |
+
[dcl.ref]: dcl.md#dcl.ref
|
| 1427 |
+
[declval]: utilities.md#declval
|
| 1428 |
+
[defns.referenceable]: intro.md#defns.referenceable
|
| 1429 |
+
[expr.alignof]: expr.md#expr.alignof
|
| 1430 |
+
[expr.type]: expr.md#expr.type
|
| 1431 |
+
[expr.unary.noexcept]: expr.md#expr.unary.noexcept
|
| 1432 |
+
[func.require]: utilities.md#func.require
|
| 1433 |
+
[functional.syn]: utilities.md#functional.syn
|
| 1434 |
+
[intseq]: #intseq
|
| 1435 |
+
[intseq.general]: #intseq.general
|
| 1436 |
+
[intseq.intseq]: #intseq.intseq
|
| 1437 |
+
[intseq.make]: #intseq.make
|
| 1438 |
+
[meta]: #meta
|
| 1439 |
+
[meta.const.eval]: #meta.const.eval
|
| 1440 |
+
[meta.general]: #meta.general
|
| 1441 |
+
[meta.help]: #meta.help
|
| 1442 |
+
[meta.logical]: #meta.logical
|
| 1443 |
+
[meta.member]: #meta.member
|
| 1444 |
+
[meta.rel]: #meta.rel
|
| 1445 |
+
[meta.rqmts]: #meta.rqmts
|
| 1446 |
+
[meta.summary]: #meta.summary
|
| 1447 |
+
[meta.trans]: #meta.trans
|
| 1448 |
+
[meta.trans.arr]: #meta.trans.arr
|
| 1449 |
+
[meta.trans.cv]: #meta.trans.cv
|
| 1450 |
+
[meta.trans.general]: #meta.trans.general
|
| 1451 |
+
[meta.trans.other]: #meta.trans.other
|
| 1452 |
+
[meta.trans.ptr]: #meta.trans.ptr
|
| 1453 |
+
[meta.trans.ref]: #meta.trans.ref
|
| 1454 |
+
[meta.trans.sign]: #meta.trans.sign
|
| 1455 |
+
[meta.type.synop]: #meta.type.synop
|
| 1456 |
+
[meta.unary]: #meta.unary
|
| 1457 |
+
[meta.unary.cat]: #meta.unary.cat
|
| 1458 |
+
[meta.unary.comp]: #meta.unary.comp
|
| 1459 |
+
[meta.unary.general]: #meta.unary.general
|
| 1460 |
+
[meta.unary.prop]: #meta.unary.prop
|
| 1461 |
+
[meta.unary.prop.query]: #meta.unary.prop.query
|
| 1462 |
+
[namespace.std]: library.md#namespace.std
|
| 1463 |
+
[ratio]: #ratio
|
| 1464 |
+
[ratio.arithmetic]: #ratio.arithmetic
|
| 1465 |
+
[ratio.comparison]: #ratio.comparison
|
| 1466 |
+
[ratio.general]: #ratio.general
|
| 1467 |
+
[ratio.ratio]: #ratio.ratio
|
| 1468 |
+
[ratio.si]: #ratio.si
|
| 1469 |
+
[ratio.syn]: #ratio.syn
|
| 1470 |
+
[special]: class.md#special
|
| 1471 |
+
[stmt.return]: stmt.md#stmt.return
|
| 1472 |
+
[support.signal]: support.md#support.signal
|
| 1473 |
+
[swappable.requirements]: library.md#swappable.requirements
|
| 1474 |
+
[term.layout.compatible.type]: basic.md#term.layout.compatible.type
|
| 1475 |
+
[term.object.type]: basic.md#term.object.type
|
| 1476 |
+
[term.odr.use]: basic.md#term.odr.use
|
| 1477 |
+
[term.scalar.type]: basic.md#term.scalar.type
|
| 1478 |
+
[term.standard.layout.type]: basic.md#term.standard.layout.type
|
| 1479 |
+
[term.trivial.type]: basic.md#term.trivial.type
|
| 1480 |
+
[term.trivially.copyable.type]: basic.md#term.trivially.copyable.type
|
| 1481 |
+
[term.unevaluated.operand]: expr.md#term.unevaluated.operand
|
| 1482 |
+
[tuple.apply]: utilities.md#tuple.apply
|
| 1483 |
+
[type.traits]: #type.traits
|
| 1484 |
+
[type.traits.general]: #type.traits.general
|