I've got the following code as an experiment:
int f1() { return 0; }
struct Bar {
Bar() = delete;
int f() { return 0; }
int operator()() { return 1; }
};
int main()
{
decltype(f1()) x = 3;//f1() is expression
result_of<decltype(&f1)()>::type x1 = 3;//type+param
result_of<Bar()>::type x3 = 3;//type+param
decltype(declval<Bar>().f()) y = 4;//expression
decltype((((Bar*)nullptr)->*(&Bar::f))()) z = 5;//expression
result_of<decltype(std::mem_fn(&Bar::f))()>::type y2 = 3;//error!!!!!!
}
Everything is OK except the last result_of
:
I was trying to get the return type of Bar::f
, using result_of
.
Why it failed, and how to correct it?
The unspecified return type of
mem_fn
:is defined in terms of
INVOKE
[func.memfn]/p1:where the definition of
INVOKE
includes the following two bullets [func.require]/p1:That is, the first argument of what
mem_fn
returns must be the type of the implicit object parameter (t1
), either a reference or a pointer, e.g.:You could also remove
std::mem_fn
altogether: