
Hi,
From: Ben Artin
In article <BAY104-DAV1150B74243DE0C91E6C3DDBF8C0@phx.gbl>, Daryle Walker <darylew@hotmail.com> wrote:
Actually, under my opinion/theory, NO function, member function, or operator returns a const non-reference. That's includes the post-increment operator. However, I don't have the "Exceptional C++" book, so I don't know the author's reasoning for his opinion.
Implement a post-increment that returns a non-const, then see what x++++ does, and you'll understand the reasoning :-)
This is the reasoning shown in "Exceptional C++" - the point is that UDTs' behaviour should be similar to built-in types whenever possible. You can't do x++++ with int, so you shouldn't be able to do this with UDTs either. Recently I found another good reason to return const value - bounds-specifier policy class contains two functions: min_value() and max_value(). These values are constant by nature (they don't change during execution of a program), so it's natural to return them as consts. This may help finding bugs, because it's not very likely that someone would want to modify on purpose the value returned from one of these functions - would it make any sence? Best regards, Robert