I am new to C ++ 11 and ask the following question when reading the C ++ 11 FAQ .
Suppose we have a function f() that returns a value in a type X, then we have the following ways to store the return value:
f
X
X a = f(); // copy assignment X&& b = f(); // move assignment
According to frequently asked questions on C ++ , the second avoids unnecessary copy.
My question is: is the second preferred way to get the return value of a function call? Also auto c = f();equivalent to one of the above appointments? Thanks.
auto c = f();
. , . / ( , X ), .
:
X a = f();
, f() a, . , auto c = f();.
f()
a
, -, . rvalue f(). Stroustrup , , rvalue-. / , rvalue.
, , . .
auto a = f() X a = f()
auto a = f()
X a = f()
X && b , .
X && b
, .. X a = f(), rvalue. () . , , , .
Source: https://habr.com/ru/post/1526419/More articles:Редактировать на месте Метеорный просмотр без использования сеанса - meteorРучки Если оператор внутри каждого теряет контекст - javascriptIs there a way to hashed a password using BCrypt in classic ASP? - securityOverloads in COM Interworking (CCW) - IDispatch names include the suffix (_2, _3, etc.) - .netScintilla Columns - c #A quick way to check 2 lists is the same C # - c #python - why is the list not changing? - pythonDoes Asp Hash (bcrypt) support Passwords like in PHP - hashcodenice hash function for struct key that has three ints - c ++Problems with changing the default inverse color in usercontrol - c #All Articles