std::experimental::ranges::SizedSentinel

From cppreference.com
< cpp‎ | experimental‎ | ranges
 
 
Technical specifications
Filesystem library (filesystem TS)
Library fundamentals (library fundamentals TS)
Library fundamentals 2 (library fundamentals 2 TS)
Extensions for parallelism (parallelism TS)
Extensions for parallelism 2 (parallelism TS v2)
Extensions for concurrency (concurrency TS)
Concepts (concepts TS)
Ranges (ranges TS)
Special mathematical functions (special math TR)
 
 
Iterators library
Iterator concepts
SizedSentinel

Indirect callable concepts
                                                  
                                                  
                                                  
Common algorithm requirements
                                                  
Concept utilities
Iterator utilities and operations
Iterator traits
Iterator adaptors
Stream iterators
 
template <class S, class I>

concept bool SizedSentinel =
  Sentinel<S, I> &&
  !ranges::disable_sized_sentinel<std::remove_cv_t<S>, std::remove_cv_t<I>> &&
  requires(const I& i, const S& s) {
    { s - i } -> Same<ranges::difference_type_t<I>>&&;
    { i - s } -> Same<ranges::difference_type_t<I>>&&;

  };
(1) (ranges TS)
template <class S, class I>
constexpr bool disable_sized_sentinel = false;
(1) (ranges TS)

The SizedSentinel 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.

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. Then SizedSentinel<S, I> is satisfied only if:

  • If N is representable by ranges::difference_type_t<I>, then s - i is well-defined and equals N; and
  • If -N is representable by ranges::difference_type_t<I>, then i - s is well-defined and equals -N.

The variable template disable_sized_sentinel provides a mechanism for iterators and sentinels that can be subtracted but do not meet the semantic requirements of SizedSentinel to opt out of the concept by specializing the variable template to have the value true.

Equality preservation

An expression is equality preserving if it results in equal outputs given equal inputs.

  • The inputs to an expression consist of its operands.
  • The outputs of an expression consist of its result and all operands modified by the expression (if any).

Every expression required to be equality preserving is further required to be stable: two evaluations of such an expression with the same input objects must have equal outputs absent any explicit intervening modification of those input objects.

Unless noted otherwise, every expression used in a requires-expression is required to be equality preserving and stable, and the evaluation of the expression may only modify its non-constant operands. Operands that are constant must not be modified.

Implicit expression variations

A requires-expression that uses an expression that is non-modifying for some constant lvalue operand also implicitly requires additional variations of that expression that accept a non-constant lvalue or (possibly constant) rvalue for the given operand unless such an expression variation is explicitly required with differing semantics. These implicit expression variations must meet the same semantic requirements of the declared expression. The extent to which an implementation validates the syntax of the variations is unspecified.