The following code:
struct A
{
int f(int);
auto g(int x) -> decltype(f(x));
};
Fails to compile with the error:
erro
Comeau doesn't like auto
as a top level return type, but the following compiles successfully:
template R get_return_type(R (C::*)(A1));
struct A
{
int f(int);
decltype(get_return_type(&A::f)) g(int x);
};
Basically, you have to declare at least one additional construct that gets you the type you want. And use decltype
directly.
EDIT: Incidentally, this works fine for diving into the return type of a member function as well:
template R get_return_type(R (C::*)(A1));
struct B { int f(int); };
struct A
{
int f(int);
B h(int);
decltype(get_return_type(&A::f)) g(int x);
decltype(get_return_type(&A::h).f(0)) k(int x);
};
int main()
{
return A().k(0);
}
Granted, it doesn't have the same convenience of auto f()-> ...
, but at least it compiles.