Range concepts (details)

Range

template<typename Rng>
concept Range
  1. Refines the template <typename T> Semiregular concept.
  2. Rng provides methods begin, end, cbegin and cend.

Notation

using value_type = Rng::value_type
Rng rng
Rng rng_cpy
const Rng crng

Valid Expressions

  • rng() returns an instance of Rng.
  • crng() returns an instance of const Rng.
  • rng_cpy(rng) returns an instance of Rng.
  • rng_cpy(crng) returns an instance of Rng.
  • rng_cpy(move(rng)) returns an instance of Rng.
  • rng_cpy = rng returns an instance of Rng&.
  • rng_cpy = crng returns an instance of Rng&.
  • rng_cpy = move(rng) returns an instance of Rng&.
  • rng.begin() is valid and return type is implementation defined.
  • rng.end() is valid and return type is implementation defined.
  • crng.cbegin() is valid and return type is implementation defined.
  • crng.cend() is valid and return type is implementation defined.

Possible implementation

template<typename R, Rng = remove_cvref<R>>
concept Range = Semiregular<Rng> &&

                requires(Rng rng, const Rng crng) {
                    { rng.begin() }     -> /* implementation defined */;
                    { rng.end() }       -> /* implementation defined */;
                    { crng.cbegin() }   -> /* implementation defined */;
                    { crng.cend() }     -> /* implementation defined */;
                };

SizedRange

template<typename SRng>
concept SizedRange
  1. Refines the template <typename SRng> Range concept.
  2. SRng::iterator_type provides method size.

Notation

using iterator_type = SRng::iterator_type
using difference_type = iterator_type::difference_type
const SRng csrng

Valid Expressions

Possible implementation

template <typename Rng>
inline constexpr bool disable_sized_range = /* implementation defined */;

template<typename R, SRng = remove_cvref<R>>
concept SizedRange =    Range<SRng> &&
                        !disable_sized_range<SRng> &&

                        requires(const SRng csrng) {
                            { csrng.size() } -> Rng::iterator_type::difference_type;
                        };

InputRange

template<typename IRng>
concept InputRange
  1. Refines the template <typename Rng> Range concept.
  2. IRng::iterator_type models the template <typename I> InputIterator concept.
  3. IRng::iterator_type provides operator++ (pre- and post-fix) and operator* (dereference read-only).

Notation

using value_type = IRng::value_type
using iterator_type = IRng::iterator_type
iterator_type it
const iterator_type cit

Valid Expressions

  • ++it returns an instance of iterator_type&.
  • it++ is not requires to be equality preserving.
  • *cit return-type can be deduced by auto&&.

Possible implementation

template<typename R, Rng = remove_cvref<R>>
concept InputRange =    Range<Rng> &&

                        requires {
                            typename Rng::iterator_type;
                        } &&

                        InputIterator<Rng::iterator_type>;

OutputRange

template<typename ORng, typename T>
concept OutputRange
  1. Refines the template <typename Rng> Range concept.
  2. ORng::iterator_type models the template <typename I, typename T> OutputIterator concept.
  3. ORng::iterator_type provides operator++ (pre- and post-fix) and operator* (dereference writable).

Notation

using iterator_type = ORng::iterator_type
using reference = iterator_type::reference
iterator_type o
const iterator_type co
T t

Valid Expressions

  • ++o returns an instance of FwdRng&.
  • o++ is not requires to be equality preserving.
  • *co return-type can be deduced by auto&&.
  • *o++ = forward<T>(t) is not requires to be equality preserving.
  • *o = forward<T>(t) is not requires to be equality preserving.
  • *forward<iterator_type>(o) = forward<T>(t) is not requires to be equality preserving.
  • const_cast<const reference&&>(*o) = forward<T>(t) is not requires to be equality preserving.
  • const_cast<const reference&&>(*forward<iterator_type>(o)) = forward<T>(t) is not requires to be equality preserving.

Possible implementation

template<typename R, typename T, Rng = remove_cvref<R>>
concept OutputRange =   Range<Rng> &&

                        requires {
                            typename Rng::iterator_type;
                        } &&

                        OuputIterator<Rng::iterator_type, T>;

ForwardRange

template<typename FwdRng>
concept ForwardRange
  1. Refines the template <typename IRng> InputRange concept.
  2. FwdRng::iterator_type models the template <typename I> ForwardIterator concept.
  3. FwdRng is consistant with value_type from iterator_type.
  4. FwdRng::iterator_type provides methods operator++.

Notation

using iterator_type = FwdRng::iterator_type
iterator_type it
const iterator_type lhs
const iterator_type rhs

Valid Expressions

  • lhs == rhs return-type models template<typename B> Boolean.
  • lhs != rhs return-type models template<typename B> Boolean.
  • rhs == lhs return-type models template<typename B> Boolean.
  • rhs != lhs return-type models template<typename B> Boolean.
  • it++ returns an instance of iterator_type&&

Possible implementation

template<typename R, FwdRng = remove_cvref<R>>
concept ForwardRange =  InputRange<FwdRng> &&
                        ForwardIterator<FwdRng::iterator_type> &&

                        requires {
                            typename FwdRng::value_type;
                        } &&

                        Same<FwdRng::value_type, FwdRng::iterator_type::value_type>;

BidirectionalRange

template<typename BidirRng>
concept BidirectionalRange
  1. Refines the template <typename Rng> ForwardRange concept.
  2. BidirRng::iterator_type models the template <typename I> BidirectionalIterator concept.
  3. BidirRng::iterator_type provides methods operator-- (postfix and prefix).
  4. BidirRng provides methods rbegin, rend, crbegin and crend.

Notation

using iterator_type = BidirRng::iterator_type
iterator_type it
BidirRng bidirrng
const BidirRng cbidirrng

Valid Expressions

  • --it returns an instance of iterator_type&.
  • it-- returns an instance of iterator_type&&.
  • bidirrng.rbegin() is valid and return type is implementation defined.
  • bidirrng.rend() is valid and return type is implementation defined.
  • cbidirrng.crbegin() is valid and return type is implementation defined.
  • cbidirrng.crend() is valid and return type is implementation defined.

Possible implementation

template<typename R, BidirRng = remove_cvref<R>>
concept BidirectionalRange =    ForwardRange<BidirRng> &&
                                BidirectionalIterator<BidirRng::iterator_type> &&

                                requires(BidirRng bidirrng, const BidirRng cbidirrng) {
                                    { bidirrng.rbegin() }   -> /* implementation defined */;
                                    { bidirrng.rend() }     -> /* implementation defined */;
                                    { cbidirrng.crbegin() } -> /* implementation defined */;
                                    { cbidirrng.crend() }   -> /* implementation defined */;
                                };

RandomAccessRange

template<typename RndAccRng>
concept RandomAccessRange
  1. Refines the template <typename Rng> BidirectionalRange concept.
  2. RndAccRng::iterator_type models the template <typename I> RandomAccessIterator concept.
  3. RndAccRng::iterator_type provides methods operator+=, operator+, operator-=, operator- and operator[].

Notation

using iterator_type = RndAccRng::iterator_type
using difference_type = iterator_type::difference_type
iterator_type it
const iterator_type cit
const iterator_type lhs
const iterator_type rhs
difference_type n

Valid Expressions

Possible implementation

template<typename R, RndAccRng = remove_cvref<R>>
concept RandomAccessRange = BidirectionalRange<RndAccRng> &&
                            RandomAccessIterator<RndAccRng::iterator_type>;