Andre Poenitz <[EMAIL PROTECTED]> writes:
| I don't really know. There are only a few places where this would be
| a (disputable) advantage for consistency reasons.
:-) true I guess.... but it is part of the "programming-by-contract"
paradigm and also a way to ensure that tempraries are not modified. (a
thing that is usually sloppy programming or just plain wrong.)
During te change to string const I did not ave to change any code.
Also for complex objects const objects are a lot faster to work with.
(for PODs using const return are of no value, since you can't modify
their temporaries anyway)
|
| In general _I_ prefer returning a "nonconst" string that can be used in the
| same way as the const string plus in some contexts where one you really
| like to do modify the string without creating an additional temporary.
I followed the advice I got from Herb Sutters Exceptional C++.
| Performance-wise the two should be identical (well, that might depend
| somewhat on your optimizer).
Not really.
think:
string const getStr() { return someStr; }
string getStr() { return SomeStr; }
char a = getStr()[5];
The const returning getStr will be a lot faster and be able to take
advantage of reference counting. (ok the exaple is not perfect...)
Lgb