At here,cppreference-lvalue,I found that
Cast expression to rvalue reference to function is lvalue.
I was curious, so I carried out the following experiment:
#include <iostream>
using namespace std;
typedef void (&&funr) (int);
typedef void (&funl) (int);
void test(int num){
cout<<num<<endl;//output:20
}
void foo(funr fun){
fun(10);
}
void foo(funl fun){
fun(20);//call this
}
template <typename T> void foo(T&& fun){
cout<<is_same<T,void(&)(int)>::value<<endl;//true, it is lvalue.
cout<<is_same<T,void(int)>::value<<endl;//false, it isn't rvalue.
}
int main()
{
foo(static_cast<void(&&)(int)>(test));
return 0;
}
the fact that so.
Why cast expression to rvalue reference to function is lvalue? Is it because a function type is no need to move semantics or something else? Or I understand this word wrong.
Cast expression to rvalue reference to function is lvalue
Aucun commentaire:
Enregistrer un commentaire