Your question has some most important part in the end in the fine print. If your foo
is a template, C++17 deduction guides won't help you with a simple syntax like
std::function f(foo);
You'd still need to provide template arguments for foo
. Assuming you are OK with specifying foo
's argument types (as you have to be) writing make_func is a trivial exercise:
template<class R, class... ARGS>
auto make_func(R (*ptr)(ARGS...)) {
return std::function<R (*)(ARGS...)>(ptr);
}
And than you use it:
auto bar = make_func(&foo<Z, Y, Z>);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…