| Iterator concepts | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Iterator primitives | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Algorithm concepts and utilities | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Indirect callable concepts | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Common algorithm requirements | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Utilities | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Iterator adaptors | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
template<class T> constexprbool/*is-integer-like*/=/* see description */; | (1) | (since C++20) (exposition only*) |
template<class T> constexprbool/*is-signed-integer-like*/=/* see description */; | (2) | (since C++20) (exposition only*) |
T is an integer-like type.T is a signed-integer-like type.Contents |
A typeT is aninteger-class type if it is in a set of implementation-defined types that behave asinteger types do, as definedbelow. An integer-class type is not necessarily aclass type.
An integer-class type can represent\(\scriptsize 2^N \)2N
consecutive integers, whereN, a positive integer, is called thewidth of the integer-class type.
An integer-class type is either signed or unsigned:
[\(\scriptsize -2^{N-1} \)-2N-1, \(\scriptsize 2^{N-1}-1 \)2N-1], whereN is greater than the width of every signed integral type.[\(\scriptsize 0 \)0, \(\scriptsize 2^N-1 \)2N], whereN is greater than the width of every unsigned integral type.All integer-class types modelregular andthree_way_comparable<std::strong_ordering>.
Avalue-initialized object of integer-class type has value0.
An expressionE of integer-class typeT iscontextually convertible tobool as if bybool(E!= T(0)).
A type other than (possibly cv-qualified)bool isinteger-like if it modelsintegral or if it is an integer-class type.
signed_integral or if it is a signed-integer-class type.unsigned_integral or if it is an unsigned-integer-class type.Expressions of integer-class type are explicitly convertible to any integer-like type, and implicitly convertible to any integer-class type of equal or greater width and the same signedness. Expressions of integral type are both implicitly and explicitly convertible to any integer-class type. Conversions between integral and integer-class types and between two integer-class types do not exit via an exception. The result of such a conversion is the unique value of the destination type that is congruent to the source modulo\(\scriptsize 2^N \)2N
, whereN is the width of the destination type.
LetInt<T> denote the following type:
T is an integer-class type,Int<T> is a unique hypotheticalextended integer type of the same signedness with the same width asT.T is an integral type, letInt<T> is the same type asT.Given the following types, values and operators:
| Type | Definition |
IC | an integer-class type |
IL | an integer-like type |
| Value | Definition |
| a | an object of typeIC |
| b | an object of typeIL |
| c | an lvalue of an integeral type |
| x | an object of typeInt<IC> that represent the same value asa |
| y | an object of typeInt<IL> that represent the same value asb |
| Operator | Definition |
| @= | one of+=,-=,*=,/=,%=,&=,|=,^=,<<= and>>= |
| @ | one of+,-,*,/,%,&,|,^,<<,>>,&&,||,==,!=,<,>,<=,>=,<=> and, |
The following expressions must be well-formed and have their specified result and effects if the specified conditions are satisfied:
| Expression | Condition | Result | Effects |
|---|---|---|---|
| a++ | No condition | a prvalue of typeIC whose value is equal to that ofa prior to the evaluation | modifies the value ofa by adding1 to it |
| a-- | modifies the value ofa by subtracting1 to it | ||
| ++a | expression-equivalent toa+=1 | ||
| --a | expression-equivalent toa-=1 | ||
| &a | expression-equivalent tostd::addressof(a) | ||
| !a | !x is well-formed | same as!x | |
| +a | +x is well-formed | same as+x, but has typeIC | same as+x |
| -a | -x is well-formed | same as-x, but has typeIC | same as-x |
| ~a | ~x is well-formed | same as~x, but has typeIC | same as~x |
| c @= a | c @= x is well-formed | an lvalue referring toc | same asc @= x |
| a @= b | x @= y is well-formed | an lvalue referring toa | same asx @= y, except that the value that would be stored intox is stored intoa |
| a @ b | x @ y is well-formed | same asx @ y, but the result type is different:
| same asx @ y |
| b @ a | y @ x is well-formed | same asy @ x, but the result type is different:
| same asy @ x |
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
| DR | Applied to | Behavior as published | Correct behavior |
|---|---|---|---|
| LWG 3366 (P2393R1) | C++20 | the conversion between an integer-class type and its corresponding integer type was not guaranteed to produce a representable value | guaranteed |
| LWG 3376 (P2393R1) | C++20 | integer-class types could only be class types | also allowed non-class types |
| LWG 3467 | C++20 | bool was considered as an integer-like type | excluded |
| LWG 3575 (P2393R1) | C++20 | integer-class types were not guaranteed to be three-way-comparable | guaranteed |
(C++20) | specifies that asemiregular type can be incremented with pre- and post-increment operators(concept)[edit] |