More "closely", as far as I understand, means you want to specify the function arguments of print
. That is, for example, you select int, int
, then get back the result-type of Foo{}.print(int{},int{})
, and thereafter construct a function pointer from all the available information.
Here is an alias template which does that for you in a general way:
template<typename ... Args>
using ptr_to_print_type = decltype(std::declval<Foo>().print(std::declval<Args>() ...)) (Foo::*)(Args ...);
You could also use std::result_of
instead of the std::declval
stuff, but I like the latter more.
You can use the above as
func<ptr_to_print_type<int,int> >();
EDIT: as asked for by @JavaLover, which btw seems like an unsuitable name for such horrible C++ shit :-), here is the same as above using std::result_of
(untested now tested and wrong):
//------ does not compile for overloaded functions --------
template<typename ... Args>
using ptr_to_print_type = std::result_of_t<decltype(&Foo::print)(Foo, Args ...)> (Foo::*)(Args ...)
//------ does not compile for overloaded functions --------
You could further abstract away the Foo
but not the print
(unless you're using macros).