mirror of
https://github.com/isocpp/CppCoreGuidelines.git
synced 2025-12-18 21:24:41 +03:00
Improve reasoning and examples for F.48 (#2100)
* fix incorrect reason for F.48 * distinguish rvo and nrvo * the issue is about local, so limiting example to local --------- Co-authored-by: Sergey Zubkov <cubbi@cubbi.com>
This commit is contained in:
@@ -3932,11 +3932,13 @@ value) of any assignment operator.
|
|||||||
|
|
||||||
##### Reason
|
##### Reason
|
||||||
|
|
||||||
With guaranteed copy elision, it is now almost always a pessimization to expressly use `std::move` in a return statement.
|
Returning a local variable implicitly moves it anyway.
|
||||||
|
An explicit `std::move` is always a pessimization, because it prevents Return Value Optimization (RVO),
|
||||||
|
which can eliminate the move completely.
|
||||||
|
|
||||||
##### Example, bad
|
##### Example, bad
|
||||||
|
|
||||||
S f()
|
S bad()
|
||||||
{
|
{
|
||||||
S result;
|
S result;
|
||||||
return std::move(result);
|
return std::move(result);
|
||||||
@@ -3944,9 +3946,10 @@ With guaranteed copy elision, it is now almost always a pessimization to express
|
|||||||
|
|
||||||
##### Example, good
|
##### Example, good
|
||||||
|
|
||||||
S f()
|
S good()
|
||||||
{
|
{
|
||||||
S result;
|
S result;
|
||||||
|
// Named RVO: move elision at best, move construction at worst
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user