The capture function decorator is used to capture values in a function. It provides more flexibility in capturing than the lambda capture list in C++. It provides a way to do move and perfect capturing. The values captured are prepended to the argument list of the function that will be called.


// Capture by decaying each value
template<class... Ts>
constexpr auto capture(Ts&&... xs);

// Capture lvalues by reference and rvalue reference by reference
template<class... Ts>
constexpr auto capture_forward(Ts&&... xs);

// Capture lvalues by reference and rvalues by value.
template<class... Ts>
constexpr auto capture_basic(Ts&&... xs);


assert(capture(xs...)(f)(ys...) == f(xs..., ys...));


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

struct sum_f
    template<class T, class U>
    T operator()(T x, U y) const
        return x+y;

int main() {
    auto add_one = fit::capture(1)(sum_f());
    assert(add_one(2) == 3);