Difference between revisions of "cpp/iterator/sized sentinel for"
(copy from cpp/experimental/ranges/iterator/SizedSentinel) |
m |
||
Line 20: | Line 20: | ||
@1@ The {{tt|sized_sentinel_for}} concept specifies that an object of the iterator type {{tt|I}} and an object of the sentinel type {{tt|S}} can be subtracted to compute the distance between them in constant time. | @1@ The {{tt|sized_sentinel_for}} concept specifies that an object of the iterator type {{tt|I}} and an object of the sentinel type {{tt|S}} can be subtracted to compute the distance between them in constant time. | ||
− | @2@ The {{tt|disable_sized_sentinel_for}} variable template can be used to prevent iterators and sentinels that can be subtracted but do not actually model {{tt|sized_sentinel_for}} | + | @2@ The {{tt|disable_sized_sentinel_for}} variable template can be used to prevent iterators and sentinels that can be subtracted but do not actually model {{tt|sized_sentinel_for}} from satisfying the concept.<br> |
The variable template is allowed to be specialized for cv-unqualified non-array object type {{tt|S}} and {{tt|I}}, as long as at least one of which is a program-defined type. Such specializations shall be usable in [[cpp/language/constant expression|constant expressions]] and have type {{c|const bool}}. | The variable template is allowed to be specialized for cv-unqualified non-array object type {{tt|S}} and {{tt|I}}, as long as at least one of which is a program-defined type. Such specializations shall be usable in [[cpp/language/constant expression|constant expressions]] and have type {{c|const bool}}. | ||
Revision as of 22:19, 21 June 2020
Defined in header <iterator>
|
||
template<class S, class I> concept sized_sentinel_for = |
(1) | (since C++20) |
template<class S, class I> inline constexpr disable_sized_sentinel_for = false; |
(2) | (since C++20) |
sized_sentinel_for
concept specifies that an object of the iterator type I
and an object of the sentinel type S
can be subtracted to compute the distance between them in constant time. disable_sized_sentinel_for
variable template can be used to prevent iterators and sentinels that can be subtracted but do not actually model sized_sentinel_for
from satisfying the concept.The variable template is allowed to be specialized for cv-unqualified non-array object type
S
and I
, as long as at least one of which is a program-defined type. Such specializations shall be usable in constant expressions and have type const bool.Semantic requirements
Let i
be an iterator of type I
, and s
a sentinel of type S
such that [i, s)
denotes a range. Let n
be the smallest number of applications of ++i
necessary to make bool(i == s) be true
. sized_sentinel_for<S, I>
is satisfied only if:
- If
n
is representable by std::iter_difference_t<I>, then s - i is well-defined and equalsn
; and - If
-n
is representable by std::iter_difference_t<I>, then i - s is well-defined and equals-n
. - Subtraction between
i
ands
has constant time complexity.
Equality preservation
Expressions declared in requires expressions of the standard library concepts are required to be equality-preserving (except where stated otherwise).
Implicit expression variations
A requires expression that uses an expression that is non-modifying for some constant lvalue operand also requires implicit expression variations.