LValue RValue

LValue RValue


https://msdn.microsoft.com/zh-cn/library/f90831hc.aspx


An lvalue refers to an object that persists beyond a single expression.You can think of an lvalue as an object that has a name.All variables, including nonmodifiable (const) variables, are lvalues.An rvalue is a temporary value that does not persist beyond the expression that uses it.


LValue and RValue reference

https://msdn.microsoft.com/zh-cn/library/dd293668.aspx


RValue reference usage:

1 Move Semantics

2 Perfect Forwarding. use std::forward.

3 Additional Properties of Rvalue References
You can overload a function to take an lvalue reference and an rvalue reference. 

The compiler treats a named rvalue reference as an lvalue and an unnamed rvalue reference as an rvalue.

You can cast an lvalue to an rvalue reference. use std::move.

4 Function templates deduce their template argument types and then use reference collapsing rules.

猜你喜欢

转载自blog.csdn.net/zhaozhencn/article/details/51026758