On 2/5/2016 2:50 AM, JiiPee wrote:
> On 04/02/2016 23:53, Alf P. Steinbach wrote:
>>
>> [const result value] was once recommended by Scott Meyers. Then
>> came move semantics, and Andrei Alexandrescu declared that advice
>> dead (actually, as I recall, that was /before/ C++11, just with
>> Andrei's own C++03-compatible move semantics scheme called Mojo).
>> There was a slightly memorable quote that I don't recall, but
>> anyway, if you make the return value `const` then it can't be
>> efficiently moved from, so that's ungood.
>
> ok, so not been able to move is worse than a danger that somebody
> does: a.getName() = "Peter";
Yes, a restriction on useful and sometimes critical functionality is
more important than preventing someone from doing a harmless silly thing.
On a personal note, I never adopted the `const` return value convention
in C++03, because I didn't see the point doing extra work and making the
code more verbose in order to prevent a (as I saw it) non-problem.
Scott Meyers made up for his (IMO) bad advice about result values, which
was in the way of move semantics, by posting in this very group a
critique of the then proposed rules for automatic generation of move
constructors and assignment operators. He pointed out more situations
where there was effectively a class invariant, and that a moved from
object should always be destructible and, if previously assignable,
still assignable (OK, a detail here or there may be wrong, I don't
remember this exactly). As a result the proposed rules were changed.
Cheers!,
- Alf