Algorithms

This module provides overloads of standard algorithms that leverage the internal structure of the immutable containers to provide faster iteration. These are drop-in replacements of the respective STL algorithms that can be a few times faster when applied on immutable sequences.

For further convenience they can be passed in just a container where the standard library algorithms require being passed in two iterators.

Note

They are a similar idea to structure-aware iterators but implemented using higher order functions in order to support structures of any depth. The downside is that this sometimes causes the compiler to generate bigger executable files.


template <typename Range, typename Fn>
void immer::for_each_chunk(const Range &r, Fn &&fn)

Apply operation fn for every contiguous chunk of data in the range sequentially. Each time, Fn is passed two value_type pointers describing a range over a part of the vector. This allows iterating over the elements in the most efficient way.

Tip

This is a low level method. Most of the time, other wrapper algorithms should be used instead.

template <typename Iterator, typename Fn>
void immer::for_each_chunk(const Iterator &first, const Iterator &last, Fn &&fn)
template <typename T, typename Fn>
void immer::for_each_chunk(const T *first, const T *last, Fn &&fn)
template <typename Range, typename Fn>
bool immer::for_each_chunk_p(const Range &r, Fn &&fn)

Apply operation fn for every contiguous chunk of data in the range sequentially, until fn returns false. Each time, Fn is passed two value_type pointers describing a range over a part of the vector. This allows iterating over the elements in the most efficient way.

Tip

This is a low level method. Most of the time, other wrapper algorithms should be used instead.

template <typename Iterator, typename Fn>
bool immer::for_each_chunk_p(const Iterator &first, const Iterator &last, Fn &&fn)
template <typename T, typename Fn>
bool immer::for_each_chunk_p(const T *first, const T *last, Fn &&fn)
template <typename Range, typename T>
T immer::accumulate(Range &&r, T init)

Equivalent of std::accumulate applied to the range r.

template <typename Range, typename T, typename Fn>
T immer::accumulate(Range &&r, T init, Fn fn)
template <typename Iterator, typename T>
T immer::accumulate(Iterator first, Iterator last, T init)

Equivalent of std::accumulate applied to the range \( [first, last) \).

template <typename Iterator, typename T, typename Fn>
T immer::accumulate(Iterator first, Iterator last, T init, Fn fn)
template <typename Range, typename Fn>
Fn &&immer::for_each(Range &&r, Fn &&fn)

Equivalent of std::for_each applied to the range r.

template <typename Iterator, typename Fn>
Fn &&immer::for_each(Iterator first, Iterator last, Fn &&fn)

Equivalent of std::for_each applied to the range \( [first, last) \).

template <typename Range, typename OutIter>
OutIter immer::copy(Range &&r, OutIter out)

Equivalent of std::copy applied to the range r.

template <typename InIter, typename OutIter>
OutIter immer::copy(InIter first, InIter last, OutIter out)

Equivalent of std::copy applied to the range \( [first, last) \).

template <typename Range, typename Pred>
bool immer::all_of(Range &&r, Pred p)

Equivalent of std::all_of applied to the range r.

template <typename Iter, typename Pred>
bool immer::all_of(Iter first, Iter last, Pred p)

Equivalent of std::all_of applied to the range \( [first, last) \).