Dec 17, 2023

[C++] all expressions that are references to functions are lvalues

A special rule in the C++ standard states that all expressions that are references to functions are lvalues.

Thus we can bind a non-const lvalue reference to a function marked with std::move() because a function marked with std::move() is still an lvalue.
 

void f(int) {}

void(&fref1)(int) = f; // fref1 is an lvalue
void(&&fref2)(int) = f; // fref2 is also an lvalue

auto& ar = std::move(f); // OK: ar is lvalue of type void(&)(int)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.