How can I obtain the result type of a template member function?
The following minimal example illustrates the problem.
#include <type_traits>
template <typename U>
struct A {
};
struct B {
template <typename F = int>
A<F> f() { return A<F>{}; }
using default_return_type = std::invoke_result_t<decltype(f)>;
};
int main()
{
B::default_return_type x{};
return 0;
}
See it live on Coliru.
The code does not compile, giving error:
main.cpp:11:63: error: decltype cannot resolve address of overloaded function
11 | using default_return_type = std::invoke_result_t;
What is the correct syntax to obtain the type of B::f
with the template parameter F
set to default?