tmp/tmpx85c1n2y/{from.md → to.md}
RENAMED
|
@@ -5,99 +5,126 @@ that can be incremented with the pre- and post-increment operators. The
|
|
| 5 |
increment operations are not required to be equality-preserving, nor is
|
| 6 |
the type required to be `equality_comparable`.
|
| 7 |
|
| 8 |
``` cpp
|
| 9 |
template<class T>
|
| 10 |
-
|
| 11 |
|
| 12 |
template<class T>
|
| 13 |
-
|
| 14 |
|
| 15 |
template<class I>
|
| 16 |
concept weakly_incrementable =
|
| 17 |
-
|
| 18 |
requires(I i) {
|
| 19 |
typename iter_difference_t<I>;
|
| 20 |
requires is-signed-integer-like<iter_difference_t<I>>;
|
| 21 |
{ ++i } -> same_as<I&>; // not required to be equality-preserving
|
| 22 |
i++; // not required to be equality-preserving
|
| 23 |
};
|
| 24 |
```
|
| 25 |
|
| 26 |
A type `I` is an *integer-class type* if it is in a set of
|
| 27 |
-
implementation-defined
|
| 28 |
-
defined
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
The range of representable values of an integer-class type is the
|
| 31 |
-
continuous set of values over which it is defined.
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
*signed-integer-class type*
|
| 35 |
-
*unsigned-integer-class type*.
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
|
|
|
|
|
|
| 41 |
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
as `
|
| 45 |
-
type.
|
| 46 |
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
- For every assignment operator `@=` for which `c @= x` is well-formed,
|
| 53 |
`c @= a` shall also be well-formed and shall have the same value and
|
| 54 |
effects as `c @= x`. The expression `c @= a` shall be an lvalue
|
| 55 |
referring to `c`.
|
| 56 |
-
- For every
|
| 57 |
-
`a @ b` shall also be well-formed and shall have the same
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
|
|
|
|
|
|
|
|
|
| 66 |
|
| 67 |
An expression `E` of integer-class type `I` is contextually convertible
|
| 68 |
to `bool` as if by `bool(E != I(0))`.
|
| 69 |
|
| 70 |
All integer-class types model `regular` [[concepts.object]] and
|
| 71 |
-
`
|
| 72 |
|
| 73 |
A value-initialized object of integer-class type has value 0.
|
| 74 |
|
| 75 |
For every (possibly cv-qualified) integer-class type `I`,
|
| 76 |
-
`numeric_limits<I>` is specialized such that
|
|
|
|
|
|
|
| 77 |
|
| 78 |
-
- `
|
| 79 |
-
- `
|
| 80 |
-
|
| 81 |
-
- `
|
| 82 |
-
-
|
| 83 |
-
- `numeric_limits<I>::digits` is equal to the width of the integer-class
|
| 84 |
-
type,
|
| 85 |
-
- `numeric_limits<I>::digits10` is equal to
|
| 86 |
-
`static_cast<int>(digits * log10(2))`, and
|
| 87 |
-
- `numeric_limits<I>::min()` and `numeric_limits<I>::max()` return the
|
| 88 |
-
lowest and highest representable values of `I`, respectively, and
|
| 89 |
-
`numeric_limits<I>::lowest()` returns `numeric_limits<I>::{}min()`.
|
| 90 |
-
|
| 91 |
-
A type `I` is *integer-like* if it models `integral<I>` or if it is an
|
| 92 |
-
integer-class type. A type `I` is *signed-integer-like* if it models
|
| 93 |
-
`signed_integral<I>` or if it is a signed-integer-class type. A type `I`
|
| 94 |
-
is *unsigned-integer-like* if it models `unsigned_integral<I>` or if it
|
| 95 |
-
is an unsigned-integer-class type.
|
| 96 |
|
| 97 |
`is-integer-like<I>` is `true` if and only if `I` is an integer-like
|
| 98 |
-
type. `is-signed-integer-like<I>` is `true` if and only if I is a
|
| 99 |
signed-integer-like type.
|
| 100 |
|
| 101 |
Let `i` be an object of type `I`. When `i` is in the domain of both pre-
|
| 102 |
and post-increment, `i` is said to be *incrementable*. `I` models
|
| 103 |
`weakly_incrementable<I>` only if
|
|
@@ -106,13 +133,16 @@ and post-increment, `i` is said to be *incrementable*. `I` models
|
|
| 106 |
- If `i` is incrementable, then both `++i` and `i++` advance `i` to the
|
| 107 |
next element.
|
| 108 |
- If `i` is incrementable, then `addressof(++i)` is equal to
|
| 109 |
`addressof(i)`.
|
| 110 |
|
| 111 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
imply that `++a` equals `++b`. (Equality does not guarantee the
|
| 113 |
-
substitution property or referential transparency.)
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
algorithms can be used with istreams as the source of the input data
|
| 117 |
-
through the `istream_iterator` class template. — *end note*]
|
| 118 |
|
|
|
|
| 5 |
increment operations are not required to be equality-preserving, nor is
|
| 6 |
the type required to be `equality_comparable`.
|
| 7 |
|
| 8 |
``` cpp
|
| 9 |
template<class T>
|
| 10 |
+
constexpr bool is-integer-like = see below; // exposition only
|
| 11 |
|
| 12 |
template<class T>
|
| 13 |
+
constexpr bool is-signed-integer-like = see below; // exposition only
|
| 14 |
|
| 15 |
template<class I>
|
| 16 |
concept weakly_incrementable =
|
| 17 |
+
movable<I> &&
|
| 18 |
requires(I i) {
|
| 19 |
typename iter_difference_t<I>;
|
| 20 |
requires is-signed-integer-like<iter_difference_t<I>>;
|
| 21 |
{ ++i } -> same_as<I&>; // not required to be equality-preserving
|
| 22 |
i++; // not required to be equality-preserving
|
| 23 |
};
|
| 24 |
```
|
| 25 |
|
| 26 |
A type `I` is an *integer-class type* if it is in a set of
|
| 27 |
+
*implementation-defined* types that behave as integer types do, as
|
| 28 |
+
defined below.
|
| 29 |
+
|
| 30 |
+
[*Note 1*: An integer-class type is not necessarily a class
|
| 31 |
+
type. — *end note*]
|
| 32 |
|
| 33 |
The range of representable values of an integer-class type is the
|
| 34 |
+
continuous set of values over which it is defined. For any integer-class
|
| 35 |
+
type, its range of representable values is either -2ᴺ⁻¹ to 2ᴺ⁻¹-1
|
| 36 |
+
(inclusive) for some integer N, in which case it is a
|
| 37 |
+
*signed-integer-class type*, or 0 to 2ᴺ-1 (inclusive) for some integer
|
| 38 |
+
N, in which case it is an *unsigned-integer-class type*. In both cases,
|
| 39 |
+
N is called the *width* of the integer-class type. The width of an
|
| 40 |
+
integer-class type is greater than that of every integral type of the
|
| 41 |
+
same signedness.
|
| 42 |
|
| 43 |
+
A type `I` other than cv `bool` is *integer-like* if it models
|
| 44 |
+
`integral<I>` or if it is an integer-class type. An integer-like type
|
| 45 |
+
`I` is *signed-integer-like* if it models `signed_integral<I>` or if it
|
| 46 |
+
is a signed-integer-class type. An integer-like type `I` is
|
| 47 |
+
*unsigned-integer-like* if it models `unsigned_integral<I>` or if it is
|
| 48 |
+
an unsigned-integer-class type.
|
| 49 |
|
| 50 |
+
For every integer-class type `I`, let `B(I)` be a unique hypothetical
|
| 51 |
+
extended integer type of the same signedness with the same width
|
| 52 |
+
[[basic.fundamental]] as `I`.
|
|
|
|
| 53 |
|
| 54 |
+
[*Note 2*: The corresponding hypothetical specialization
|
| 55 |
+
`numeric_limits<B(I)>` meets the requirements on `numeric_limits`
|
| 56 |
+
specializations for integral types [[numeric.limits]]. — *end note*]
|
| 57 |
+
|
| 58 |
+
For every integral type `J`, let `B(J)` be the same type as `J`.
|
| 59 |
+
|
| 60 |
+
Expressions of integer-class type are explicitly convertible to any
|
| 61 |
+
integer-like type, and implicitly convertible to any integer-class type
|
| 62 |
+
of equal or greater width and the same signedness. Expressions of
|
| 63 |
+
integral type are both implicitly and explicitly convertible to any
|
| 64 |
+
integer-class type. Conversions between integral and integer-class types
|
| 65 |
+
and between two integer-class types do not exit via an exception. The
|
| 66 |
+
result of such a conversion is the unique value of the destination type
|
| 67 |
+
that is congruent to the source modulo 2ᴺ, where N is the width of the
|
| 68 |
+
destination type.
|
| 69 |
+
|
| 70 |
+
Let `a` be an object of integer-class type `I`, let `b` be an object of
|
| 71 |
+
integer-like type `I2` such that the expression `b` is implicitly
|
| 72 |
+
convertible to `I`, let `x` and `y` be, respectively, objects of type
|
| 73 |
+
`B(I)` and `B(I2)` as described above that represent the same values as
|
| 74 |
+
`a` and `b`, and let `c` be an lvalue of any integral type.
|
| 75 |
+
|
| 76 |
+
- The expressions `a++` and `a--` shall be prvalues of type `I` whose
|
| 77 |
+
values are equal to that of `a` prior to the evaluation of the
|
| 78 |
+
expressions. The expression `a++` shall modify the value of `a` by
|
| 79 |
+
adding `1` to it. The expression `a--` shall modify the value of `a`
|
| 80 |
+
by subtracting `1` from it.
|
| 81 |
+
- The expressions `++a`, `--a`, and `&a` shall be expression-equivalent
|
| 82 |
+
to `a += 1`, `a -= 1`, and `addressof(a)`, respectively.
|
| 83 |
+
- For every *unary-operator* `@` other than `&` for which the expression
|
| 84 |
+
`@x` is well-formed, `@a` shall also be well-formed and have the same
|
| 85 |
+
value, effects, and value category as `@x`. If `@x` has type `bool`,
|
| 86 |
+
so too does `@a`; if `@x` has type `B(I)`, then `@a` has type `I`.
|
| 87 |
- For every assignment operator `@=` for which `c @= x` is well-formed,
|
| 88 |
`c @= a` shall also be well-formed and shall have the same value and
|
| 89 |
effects as `c @= x`. The expression `c @= a` shall be an lvalue
|
| 90 |
referring to `c`.
|
| 91 |
+
- For every assignment operator `@=` for which `x @= y` is well-formed,
|
| 92 |
+
`a @= b` shall also be well-formed and shall have the same effects as
|
| 93 |
+
`x @= y`, except that the value that would be stored into `x` is
|
| 94 |
+
stored into `a`. The expression `a @= b` shall be an lvalue referring
|
| 95 |
+
to `a`.
|
| 96 |
+
- For every non-assignment binary operator `@` for which `x @ y` and
|
| 97 |
+
`y @ x` are well-formed, `a @ b` and `b @ a` shall also be well-formed
|
| 98 |
+
and shall have the same value, effects, and value category as `x @ y`
|
| 99 |
+
and `y @ x`, respectively. If `x @ y` or `y @ x` has type `B(I)`, then
|
| 100 |
+
`a @ b` or `b @ a`, respectively, has type `I`; if `x @ y` or `y @ x`
|
| 101 |
+
has type `B(I2)`, then `a @ b` or `b @ a`, respectively, has type
|
| 102 |
+
`I2`; if `x @ y` or `y @ x` has any other type, then `a @ b` or
|
| 103 |
+
`b @ a`, respectively, has that type.
|
| 104 |
|
| 105 |
An expression `E` of integer-class type `I` is contextually convertible
|
| 106 |
to `bool` as if by `bool(E != I(0))`.
|
| 107 |
|
| 108 |
All integer-class types model `regular` [[concepts.object]] and
|
| 109 |
+
`three_way_comparable<strong_ordering>` [[cmp.concept]].
|
| 110 |
|
| 111 |
A value-initialized object of integer-class type has value 0.
|
| 112 |
|
| 113 |
For every (possibly cv-qualified) integer-class type `I`,
|
| 114 |
+
`numeric_limits<I>` is specialized such that each static data member `m`
|
| 115 |
+
has the same value as `numeric_limits<B(I)>::m`, and each static member
|
| 116 |
+
function `f` returns `I(numeric_limits<B(I)>::f())`.
|
| 117 |
|
| 118 |
+
For any two integer-like types `I1` and `I2`, at least one of which is
|
| 119 |
+
an integer-class type, `common_type_t<I1, I2>` denotes an integer-class
|
| 120 |
+
type whose width is not less than that of `I1` or `I2`. If both `I1` and
|
| 121 |
+
`I2` are signed-integer-like types, then `common_type_t<I1, I2>` is also
|
| 122 |
+
a signed-integer-like type.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
|
| 124 |
`is-integer-like<I>` is `true` if and only if `I` is an integer-like
|
| 125 |
+
type. `is-signed-integer-like<I>` is `true` if and only if `I` is a
|
| 126 |
signed-integer-like type.
|
| 127 |
|
| 128 |
Let `i` be an object of type `I`. When `i` is in the domain of both pre-
|
| 129 |
and post-increment, `i` is said to be *incrementable*. `I` models
|
| 130 |
`weakly_incrementable<I>` only if
|
|
|
|
| 133 |
- If `i` is incrementable, then both `++i` and `i++` advance `i` to the
|
| 134 |
next element.
|
| 135 |
- If `i` is incrementable, then `addressof(++i)` is equal to
|
| 136 |
`addressof(i)`.
|
| 137 |
|
| 138 |
+
*Recommended practice:* The implementaton of an algorithm on a weakly
|
| 139 |
+
incrementable type should never attempt to pass through the same
|
| 140 |
+
incrementable value twice; such an algorithm should be a single-pass
|
| 141 |
+
algorithm.
|
| 142 |
+
|
| 143 |
+
[*Note 3*: For `weakly_incrementable` types, `a` equals `b` does not
|
| 144 |
imply that `++a` equals `++b`. (Equality does not guarantee the
|
| 145 |
+
substitution property or referential transparency.) Such algorithms can
|
| 146 |
+
be used with istreams as the source of the input data through the
|
| 147 |
+
`istream_iterator` class template. — *end note*]
|
|
|
|
|
|
|
| 148 |
|