"Lakos (pg. 618) argues against returning const value, and notes that
it is redundant for builtins anyway (for example, returning "const
int"), which he notes may interfere with template instantiation."
Can someone explain what this means? Specifically, why would it
interfere with template instantiation?
Also, I'd like to hear your thoughts on which method to use.
Thanks.
-Kevin
One down-to-earth practical reason for not using const on a return
value is that using const prohibits certain advanced optimizations
such as "mojo", <URL: http://www.moderncppdesign.com/mojo/>.
More generally, it needlessly restricts the client code, e.g. from
calling non-const methods on the result, possibly template instantiation
(on the function, not the dynamic result, but I haven't really thought
about that or investigated the matter, so I cannot give details), etc.
Restrictions are good when they serve some useful purpose, e.g. to
promote abstraction, bad when they're used only for dogmatic reasons.
Hth.,
- Alf