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
#include <muu/iterators.h>
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:
- Is the object a bounded array? If so, return a pointer to the first element.
- Does the object have a member function
obj.begin()
? If so, call it and return the result. - 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_
can only call visible membersiterator() - The compiler ignores the return type of member
obj.begin()
;begin_
checks for basic LegacyIterator compatibilityiterator() - The compiler does not examine the chosen
begin()
andend()
functions as a pair;begin_
checks that both exist and return compatible types.iterator()
#include <muu/iterators.h>
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:
- Is the object a bounded array? If so, return a pointer to one-past-the-last element.
- Does the object have a member function
obj.end()
? If so, call it and return the result. - 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_
can only call visible membersiterator() - The compiler ignores the return type of member
obj.end()
;end_
checks for basic LegacyIterator compatibilityiterator() - The compiler does not examine the chosen
begin()
andend()
functions as a pair;end_
checks that both exist and return compatible types.iterator()
#include <muu/iterators.h>
template <typename B, typename E>
auto iterator_distance(B begin,
E end) constexpr noexcept
Returns the distance between two iterators.