indirect

Description

The indirect function adaptor dereferences the object before calling it.

Synopsis

template<class F>
constexpr indirect_adaptor<F> indirect(F f);

Semantics

assert(indirect(f)(xs...) == (*f)(xs...));

Requirements

F must be:

  • MoveConstructible

  • Dereferenceable

Example

#include <boost/hof.hpp>
#include <cassert>
#include <memory>
using namespace boost::hof;

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

int main() {
    int r = indirect(std::make_unique<sum>())(3,2);
    assert(r == 5);
}