auto const reverse

Return a view of the range with the elements reversed. This works for any direction that the range is used in that has a reverse. For example, first (reverse (r), front) is equivalent to first (r, back). This simply wraps the range so that the directions for all operations are converted on the fly by direction::opposite().

  • range -

    The range to be reversed. It is turned into a view before it is stored inside the return type.

  • directions -

    The directions that the view should be in. If no directions are given, the default direction is used.

const auto transform

Transform each of the elements of a range using a function.

A wrapper range that computes its elements lazily. The range is converted into a view before it is stored.
  • range -

    The range to wrap.

  • function -

    Function that is applied to elements of the underlying range. Its return value is used as an element of the transformed range. This function is called every time first() is used.

  • directions -

    (optional) Directions that should be used to convert the range into a view.

const auto zip

View a number of ranges in parallel.

This returns a range whose first element is a tuple with all the first element of the ranges passed in; the second element is a tuple of the second elements; et cetera. The types contained in the tuples are the exact return types of first() on the underlying ranges. Thus, they may well be references to the elements of the underlying ranges. This means that mutable operations are possible.

The range that is returned by zip is empty if any of the underlying are empty. This means that the range has the size equal to the shortest of the underlying ranges.

The range that is returned by zip is assignable. It can therefore be used to iterate over a tuple of homogeneous ranges.

The underlying ranges are traversed over the default direction of the first range.


std::vector <int> vi {1, 2, 3};
std::vector <double> vd {4.5, 5.5};
auto zipped = zip (vi, vd);
tuple <int, double> f = first (zipped);
assert (first (f) == 1);
assert (second (f) == 4.5);

// Copy values from vi to vd.
for (; !empty (zipped); zipped = drop (zipped)) {
    tuple <int &, double &> element = first (zipped);
    second (element) = first (element);
assert (first (vd) == 1.0);
assert (second (vd) == 2.0);

  • ranges -

    (variadic) The underlying ranges to traverse.

auto const take

Return a number of elements from a range, as a range.

The default direction is the same as the underlying range. If take() is called with a different direction than the default direction, the default direction will therefore often not actually work.

Calling take with the same direction multiple times will not lead to a recursive type. If size (direction, range) and drop (reverse (direction), n, range) are available, then the latter is used directly. take() will therefore often return exactly the same type as range.

  • range -

    The range to take the elements from.

  • number -

    The number of elements to take. If the underlying range has fewer elements, only those elements are taken.

  • direction -

    (Optional) The direction to take the elements from.

Previous topic


Next topic


This Page