The reverse_compress function adaptor uses a binary function to apply a reverse [fold] ( right fold in functional programming terms) operation to the arguments passed to the function. Additionally, an optional initial state can be provided, otherwise the first argument is used as the initial state.

The arguments to the binary function, take first the state and then the argument.


template<class F, class State>
constexpr reverse_compress_adaptor<F, State> reverse_compress(F f, State s);

template<class F>
constexpr reverse_compress_adaptor<F> reverse_compress(F f);


assert(reverse_compress(f, z)() == z);
assert(reverse_compress(f, z)(x, xs...) == f(reverse_compress(f, z)(xs...), x));
assert(reverse_compress(f)(x) == x);
assert(reverse_compress(f)(x, xs...) == f(reverse_compress(f)(xs...), x));


State must be:

  • CopyConstructible

F must be:


#include <fit.hpp>
#include <cassert>

struct max_f
    template<class T, class U>
    constexpr T operator()(T x, U y) const
        return x > y ? x : y;

int main() {
    assert(fit::reverse_compress(max_f())(2, 3, 4, 5) == 5);