Difference between revisions of "cpp/iterator/weakly incrementable"
Andreas Krug (Talk | contribs) m (fmt) |
(Removed the definition of “integer-like type”, it is in a new page now.) |
||
(3 intermediate revisions by 2 users not shown) | |||
Line 15: | Line 15: | ||
}} | }} | ||
{{dcl end}} | {{dcl end}} | ||
− | + | ||
+ | For the definition of {{c/core|/*is-signed-integer-like*/}}, see {{rlpi|is-integer-like}}{{sep}}. | ||
This concept specifies requirements on types that can be incremented with the pre- and post-increment operators, but those increment operations are not necessarily [[cpp/concepts#Equality preservation|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 [[cpp/concepts#Equality preservation|equality-preserving]], and the type itself is not required to be {{lc|std::equality_comparable}}. | ||
Line 22: | Line 23: | ||
===Semantic requirements=== | ===Semantic requirements=== | ||
− | {{ | + | For an object {{c|i}} of type {{tt|I}}, {{tt|I}} models {{tt|std::weakly_incrementable}} only if all following conditions are satisfied: |
− | * The expressions {{c|++i}} and {{c|i++}} have the same domain | + | * The expressions {{c|++i}} and {{c|i++}} have the same domain. |
− | * If {{ | + | * If {{c|i}} is incrementable, then both {{c|++i}} and {{c|i++}} advance {{c|i}}. |
− | * If {{ | + | * If {{c|i}} is incrementable, then {{c|1=std::addressof(++i) == std::addressof(i)}}. |
− | + | ||
− | + | ||
− | + | ||
===Defect reports=== | ===Defect reports=== | ||
{{dr list begin}} | {{dr list begin}} | ||
− | |||
{{dr list item|paper=P2325R3|std=C++20|before={{lconcept|default_initializable}} was required|after=not required}} | {{dr list item|paper=P2325R3|std=C++20|before={{lconcept|default_initializable}} was required|after=not required}} | ||
{{dr list end}} | {{dr list end}} |
Latest revision as of 18:40, 9 September 2024
Defined in header <iterator>
|
||
template< class I > concept weakly_incrementable = |
(since C++20) | |
For the definition of /*is-signed-integer-like*/, see is-integer-like
.
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.
[edit] Semantic requirements
For an object i of type I
, I
models std::weakly_incrementable
only if all following conditions are satisfied:
- The expressions ++i and i++ have the same domain.
- If i is incrementable, then both ++i and i++ advance i.
- If i is incrementable, then std::addressof(++i) == std::addressof(i).
[edit] Defect reports
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
DR | Applied to | Behavior as published | Correct behavior |
---|---|---|---|
P2325R3 | C++20 | default_initializable was required
|
not required |
[edit] 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) |