From 34c4b9f5259d90f5f05e86069e832da9a13d0a7d Mon Sep 17 00:00:00 2001 From: Alexey Dmitriev Date: Sat, 16 Oct 2021 06:17:41 +0300 Subject: [PATCH] Update example in F20 (#1839) Rewrite copy vs move example to actually involve copy/move as opposite to be copy elided --- CppCoreGuidelines.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CppCoreGuidelines.md b/CppCoreGuidelines.md index 27b33ba..33d649a 100644 --- a/CppCoreGuidelines.md +++ b/CppCoreGuidelines.md @@ -3078,12 +3078,13 @@ Such older advice is now obsolete; it does not add value, and it interferes with const vector fct(); // bad: that "const" is more trouble than it is worth - vector g(const vector& vx) + void g(vector& vx) { // ... 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.