Return-by-value should normally be const for non-builtin return types ..
This is incorrect - one of the relatively few bugs in GotW. const rvalues โโwere doubtful in C ++ 03 and certainly very bad in C ++ 11.
The problem is that in C ++ 03, r values โโcan have any member function called on them, not even const. This is great because you can swap or execute method chains and other things that are great and make perfect sense, but it's also bad because the compiler can't catch you when you do something stupid, like assigning him or something, It is usually a bad idea to restrict everyone from doing good things, because the caller can do something stupid. The intention is good, but it is not.
In C ++ 11, this is fixed because you can prevent member functions from calling on rvalues, and secondly, because for the semantics of movement to work correctly, the value of r must be mutable. You cannot take resources from rvalue if it is const .
As a note, the reason is that it differs from the fact that primitive types always had a special wording built into the language, which was, for example, assigning rvalues โโto illegal, so there was no need to try to ensure its implementation by making it const .
As for the template instances, I'm not really sure. This practice, as was already known, was bad by the time I started coding with C ++, so this is not what I had to deal with.
Puppy source share