How to use rvalue references? Summary of rvalue reference example usage

巴扎黑
Release: 2017-06-15 14:06:18
Original
2345 people have browsed it

1. Lvalues ​​and rvalues: There is no standard definition of lvalues ​​and rvalues ​​in C++, but there is a widely recognized saying: those that can take addresses, have names, and are non-temporary are lvalues; those that cannot take addresses , without a name, temporary is an rvalue. It can be seen that immediate values, values ​​returned by functions, etc. are all rvalues; non-anonymous objects (including variables), references returned by functions, const objects, etc. are all lvalues. In essence As understood above, the creation and destruction are controlled by the compiler behind the scenes. The programmer can only ensure that the rvalues ​​(including immediate numbers) are valid in this line of code; and the ones created by the user, whose lifetime can be known through the scope rules, are lvalue (including references to local variables and const objects returned by functions), for example: int& foo(){int tmp; return tmp;} ​ int fooo(){int tmp; ret

1. A brief analysis of rvalue references, transfer semantics and perfect forwarding in C++11

How to use rvalue references? Summary of rvalue reference example usage

#Introduction: Move semantics is an important concept for c++11, and I have always seemed to understand this concept. I recently looked through the information and felt suddenly enlightened, so by the way, I recorded rvalue references, transfer semantics and perfect forwarding in C++11 for your reference

[Related Q&A recommendations]:

c++ - Is there any const rvalue reference?

c++ - Why the return value of std::move() can be assigned to an rvalue reference

Overloaded operator - Operation in c++ Symbol overloading requires writing multiple duplicate versions (reference and rvalue reference), is there any way to simplify it

c++ - Template function that accepts rvalue reference parameters

c++ - What does "clobber the lvalue" mean?

The above is the detailed content of How to use rvalue references? Summary of rvalue reference example usage. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!