rah
rah - A range (header only) library for C++

What is a range

A range is anything that can be iterate. Typically in C++ something is a range if we can call begin(range) and end(range) on it.

How to create a range

In rah this is done by rah::iterator_range. Two way to create an iterator_range:

What is a view

A view is a range returned by a function an which doesn't modify it's input range.
The computing is often done in a "lazy" way, that is to say at the moment of iteration.
There is two kind of view:

How to make a view

template<typename R> auto retro(R&& range)
{
std::make_reverse_iterator(end(range)), std::make_reverse_iterator(begin(range)));
}
  • Then you can add a pipeable version of the function
auto retro()
{
return make_pipeable([=](auto&& range) {return retro(range); });
}

How to make an iterator

There is in rah an helper to create iterators: rah::iterator_facade There are three kind of rah::iterator_facade:

How to make a pipeable view or algorithm

Use the rah::make_pipeable function.

How to create a pipeable :

auto test_count(int i)
{
return rah::make_pipeable([=](auto&& range) { return std::count(begin(range), end(range), i); });
}

How to use a pipeable :

std::vector<int> vec{ 0, 1, 2, 2, 3 };
assert((vec | test_count(2)) == 2);