Skip to content

Commit 34c4b9f

Browse files
Update example in F20 (isocpp#1839)
Rewrite copy vs move example to actually involve copy/move as opposite to be copy elided
1 parent b35c837 commit 34c4b9f

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

CppCoreGuidelines.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3078,12 +3078,13 @@ Such older advice is now obsolete; it does not add value, and it interferes with
30783078

30793079
const vector<int> fct(); // bad: that "const" is more trouble than it is worth
30803080

3081-
vector<int> g(const vector<int>& vx)
3081+
void g(vector<int>& vx)
30823082
{
30833083
// ...
30843084
fct() = vx; // prevented by the "const"
30853085
// ...
3086-
return fct(); // expensive copy: move semantics suppressed by the "const"
3086+
vx = fct(); // expensive copy: move semantics suppressed by the "const"
3087+
// ...
30873088
}
30883089

30893090
The argument for adding `const` to a return value is that it prevents (very rare) accidental access to a temporary.

0 commit comments

Comments
 (0)