Difference between revisions of "cpp/iterator/weakly incrementable"
D41D8CD98F (Talk | contribs) m (~) |
(→Semantic requirements) |
||
Line 19: | Line 19: | ||
This concept specifies requirements on types that can be incremented with the pre- and post-increment operators, but those increment operations are not necessarily equality-preserving, and the type itself is not required to be {{lc|std::equality_comparable}}. | This concept specifies requirements on types that can be incremented with the pre- and post-increment operators, but those increment operations are not necessarily equality-preserving, and the type itself is not required to be {{lc|std::equality_comparable}}. | ||
− | + | For {{tt|std::weakly_incrementable}} types, {{c|1=a == b}} does not imply that {{c|1=++a == ++b}}. Algorithms on weakly incrementable types must be single-pass algorithms. These algorithms can be used with istreams as the source of the input data through {{lc|std::istream_iterator}}. | |
+ | |||
+ | ===Semantic requirements=== | ||
+ | {{tt|I}} models {{tt|std::weakly_incrementable}} only if given only object {{tt|i}} of type {{tt|I}}: | ||
* The expressions {{c|++i}} and {{c|i++}} have the same domain | * The expressions {{c|++i}} and {{c|i++}} have the same domain | ||
* If {{tt|i}} is incrementable, then both {{c|++i}} and {{c|i++}} advance {{tt|i}} | * If {{tt|i}} is incrementable, then both {{c|++i}} and {{c|i++}} advance {{tt|i}} | ||
* If {{tt|i}} is incrementable, then {{c|1=std::addressof(++i) == std::addressof(i)}} | * If {{tt|i}} is incrementable, then {{c|1=std::addressof(++i) == std::addressof(i)}} | ||
− | |||
− | |||
=== See also === | === See also === |
Revision as of 04:56, 2 June 2020
Defined in header <iterator>
|
||
template<class I> concept weakly_incrementable = |
(since C++20) | |
where /*is-signed-integer-like*/<I> is true if std::signed_integral<I> is true or if I is a class that behaves like a signed integer type including all operators, implicit conversions, and std::numeric_limits specializations.
This concept specifies requirements on types that can be incremented with the pre- and post-increment operators, but those increment operations are not necessarily equality-preserving, and the type itself is not required to be std::equality_comparable.
For std::weakly_incrementable
types, a == b does not imply that ++a == ++b. Algorithms on weakly incrementable types must be single-pass algorithms. These algorithms can be used with istreams as the source of the input data through std::istream_iterator.
Semantic requirements
I
models std::weakly_incrementable
only if given only object i
of type I
:
- The expressions ++i and i++ have the same domain
- If
i
is incrementable, then both ++i and i++ advancei
- If
i
is incrementable, then std::addressof(++i) == std::addressof(i)
See also
(C++20) |
specifies that the increment operation on a weakly_incrementable type is equality-preserving and that the type is equality_comparable (concept) |