Update example in F20 (#1839)

Rewrite copy vs move example to actually involve copy/move as opposite to be copy elided
pull/1843/head
Alexey Dmitriev 4 years ago committed by GitHub
parent b35c837477
commit 34c4b9f525
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -3078,12 +3078,13 @@ Such older advice is now obsolete; it does not add value, and it interferes with
const vector<int> fct(); // bad: that "const" is more trouble than it is worth const vector<int> fct(); // bad: that "const" is more trouble than it is worth
vector<int> g(const vector<int>& vx) void g(vector<int>& vx)
{ {
// ... // ...
fct() = vx; // prevented by the "const" fct() = vx; // prevented by the "const"
// ... // ...
return fct(); // expensive copy: move semantics suppressed by the "const" vx = fct(); // expensive copy: move semantics suppressed by the "const"
// ...
} }
The argument for adding `const` to a return value is that it prevents (very rare) accidental access to a temporary. The argument for adding `const` to a return value is that it prevents (very rare) accidental access to a temporary.

Loading…
Cancel
Save