template<class F, class A>
auto apply(F f, A a) {
return [f=std::move(f), a=std::move(a)](auto&& b) {
return f(std::forward<dectlype(b)>(b))(a);
}
}
The forward<decltype> is an abomination and is really in need of a language based solution, but otherwise is fairly straightforward.
[1] No type checking of the definition of course, only of instantiations. On the plus side, the returned function is polymorphic and can be called for all Bs that f can be called.
[1] No type checking of the definition of course, only of instantiations. On the plus side, the returned function is polymorphic and can be called for all Bs that f can be called.