In some situations, it is desirable to be able to erase the called one (for example, a function, function pointer, an object instance with operator() , lambda, mem_fn ), for example, in Using Boost adapters with C ++ 11 lambdas , which require a copyable and standard default type of.
std::function would be ideal, but there seems to be no way to automatically determine which signature creates an instance of std::function with. Is there an easy way to get the signature of an arbitrary called function and / or wrap it in the corresponding instance of std::function (i.e. make_function function make_function )?
In particular, I am looking for one or another of
template<typename F> using get_signature = ...; template<typename F> std::function<get_signature<F>> make_function(F &&f) { ... }
so make_function([](int i) { return 0; }) returns a std::function<int(int)> . Obviously, this would not have to work if an instance could be called by more than one signature (for example, objects with more than one, template, or default operator() s parameter).
Boost is excellent, although non-Boost solutions that are not overly complex are preferred.
Edit: answering my own question.
c ++ function lambda c ++ 11 type-inference
ecatmur Aug 09 2018-12-12T00: 00Z
source share