Iterators module

Utilities for working with iterators.

Functions

template <typename T>
auto begin_iterator(T&& iterable) -> auto constexpr noexcept
Returns the 'begin' iterator of an iterable object.
template <typename T>
auto end_iterator(T&& iterable) -> auto constexpr noexcept
Returns the 'end' iterator of an iterable object.
template <typename B, typename E>
auto iterator_distance(B begin, E end) -> auto constexpr noexcept
Returns the distance between two iterators.

Function documentation

template <typename T>
auto begin_iterator(T&& iterable) constexpr noexcept

Returns the 'begin' iterator of an iterable object.

This function tries to follow the same rules as the compiler[entity 2A] for determining the 'begin' iterator in a range-based for loop:

  1. Is the object a bounded array? If so, return a pointer to the first element.
  2. Does the object have a member function obj.begin()? If so, call it and return the result.
  3. Otherwise return the result of calling ADL-resolved free-function begin(obj).

[entity 2A] Some caveats apply:

  • The compiler ignores access level of member obj.begin(); begin_iterator() can only call visible members
  • The compiler ignores the return type of member obj.begin(); begin_iterator() checks for basic LegacyIterator compatibility
  • The compiler does not examine the chosen begin() and end() functions as a pair; begin_iterator() checks that both exist and return compatible types.

template <typename T>
auto end_iterator(T&& iterable) constexpr noexcept

Returns the 'end' iterator of an iterable object.

This function tries to follow the same rules as the compiler[entity 2A] for determining the 'end' iterator in a range-based for loop:

  1. Is the object a bounded array? If so, return a pointer to one-past-the-last element.
  2. Does the object have a member function obj.end()? If so, call it and return the result.
  3. Otherwise return the result of calling ADL-resolved free-function end(obj).

[entity 2A] Some caveats apply:

  • The compiler ignores access level of member obj.end(); end_iterator() can only call visible members
  • The compiler ignores the return type of member obj.end(); end_iterator() checks for basic LegacyIterator compatibility
  • The compiler does not examine the chosen begin() and end() functions as a pair; end_iterator() checks that both exist and return compatible types.

template <typename B, typename E>
auto iterator_distance(B begin, E end) constexpr noexcept

Returns the distance between two iterators.