C ++ 11: Why can result_of accept a functor type as lvalue_reference, but not a function type as lvalue_reference?

I have a program below:

#include<type_traits>
#include<iostream>
using namespace std;
template <class F, class R = typename result_of<F()>::type>
R call(F& f) { return f(); }

struct S {
    double operator()(){return 0.0;}
};
int f(){return 1;}
int main()
{
    S obj;
    call(obj);//ok
    call(f);//error!
    return 0;
}

Unable to compile string "call (f)". It is strange that "call (obj)" is in order.

(1) I have a similar entry in another C ++ 11 thread result_of, outputting my function type failed . But this does not mean why the functor objects are in order, but there are no functions.

(2) I'm not sure if this is due to the "R-call (F & f)": the type of the function cannot declare the value l?

(3) As long as I know, any token with a name, for example variable / function, should be considered an l-value. And in the case of a function parameter, the compiler must "expand" my function name "f" into a function pointer, right?

(4) ---- l, " (F & f)"?

, "" - , ? .

+4
1

call(f) , F , . . result_of<F()> , F() int()(), , , ++ ( , ).

, result_of<F&()>, , , . call(F& f) F(), F lvalue, , lvalue F , . :

struct S {
  double operator()()& {return 0.0;}
  void operator()()&& { }
};

result_of<F()>::type void, .

result_of<F&()>, , , F , call(f) .

(3) , , variable/function, l-. "" "f" , ?

, . . call(F&) , .

(4) ---- l, " (F & f)"?

, .

, , call(F f) not call(F& f). , result_of, F(), F - l.

+5

All Articles