On 08.11.2016 04:12, Christopher J. Pisz wrote:
> I am playing catchup on C++11 and 14 still.
>
> Once upon a time it was preferred to write a function in which you were
> returning a string, in form:
>
> void GetString(std::string & out);
>
> and it was argued that we did not want to write form:
>
> std::string GetString();
>
> in order to prevent the extra copy of the temporary that is the return
> value.
No, that was just some incompetent's advice.
Before optimizing, MEASURE.
Determine if any optimization is needed.
For optimization nearly always comes at some cost, such as the added
complexity of the purely procedural notation (it requires extra
variables, more statements, otherwise needless initializations, and so
on, and on).
After optimization, MEASURE: check if it actually improved things.
In C++03, where this advice could be made to sound plausible, you would
probably have found that the advice was plain wrong, due to factors such
as Return Value Optimization (in general) and COW strings (in g++).
> With the introduction of Move Semantics, is this still the case?
It was never the case, and it's even less the case now; all the standard
library containers are movable. :)
Cheers & hth.,
- Alf