Rvalue value and function return value

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:

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.

+4
source share
2

. , . / ( , X ), .

:

X a = f();

, f() a, . , auto c = f();.

, -, . rvalue f(). Stroustrup , , rvalue-. / , rvalue.

+5
  • , , . .

  • auto a = f() X a = f()

  • X && b , .

  • , .. X a = f(), rvalue. () . , , , .

+4

Source: https://habr.com/ru/post/1526419/


All Articles