Zen C++ Libraries
Zero-dependency re-usable components for C++
Loading...
Searching...
No Matches
iterator_range.hpp File Reference

Support for creating ranges over iterators. More...

#include <iterator>
#include <tuple>
#include <type_traits>
#include <utility>
#include "zen/config.hpp"
#include "zen/concepts.hpp"
#include "zen/compat.hpp"
#include "zen/mapped_iterator.hpp"
#include "zen/zip_iterator.hpp"

Go to the source code of this file.

Classes

class  iterator_range< IterT >
struct  _zip_accept_rvalue< T >
struct  _zip_accept_rvalue< iterator_range< IterT > >

Functions

template<typename IterT>
auto make_iterator_range (IterT &&a, IterT &&b)
template<typename IterT>
auto make_iterator_range (std::pair< IterT, IterT > &&pair)
template<range T>
auto make_iterator_range (T &container)
template<range ... Ts>
auto zip (Ts &&...args)

Detailed Description

Support for creating ranges over iterators.

Function Documentation

◆ make_iterator_range() [1/2]

template<typename IterT>
auto make_iterator_range ( IterT && a,
IterT && b )

Create an iterator_range directly out of a start iterator and an end iterator.

The resulting object has methods begin() and end(), which makes it compatible with for-loops.

See also
make_iterator_range(std::pair<IterT, IterT>&& )

◆ make_iterator_range() [2/2]

template<typename IterT>
auto make_iterator_range ( std::pair< IterT, IterT > && pair)

Construct an iterator range from a pair of iterators.

This function is especially useful for methods in the standard library that return such a pair of iterators, such as std::unordered_map::equal_range.

#include <utility>
#include <iostream>
#include <unordered_map>
int main() {
std::unordered_multimap<int, int> map { { 1, 1 }, { 2, 2 }, { 2, 3} };
for (auto [k, v]: zen::make_iterator_range(std::as_const(map).equal_range(2))) {
std::cerr << k << " = " << v << "\n";
}
}
Support for creating ranges over iterators.
See also
make_iterator_range(IterT&&, IterT&&)

◆ zip()

template<range ... Ts>
auto zip ( Ts &&... args)

Create an iterator_range that zips over the given arguments.

To create a zipper that only holds constant references, use std::as_const