Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2005-04-26 11:44:19


Daniel, I am Cc:'ing you because IIRC you are the maintainer.

"Philippe Mori" <philippe_mori_at_[hidden]> writes:

>> I have found a couple of "undocumented features" in operators.hpp:
>>
>> 1) The return values from a lot of the binary operators should be
>> declared const, so that it is not possible to assign to the
>> temporary object that results from the operation. An example:
>>
>> if(!(a/b=c/d))...
>
> Well, operators are generally defined in the same form as predefined
> operators and thus does not returns const objects.
>
> You might look into the book "C++ Coding Standard" by Herb
> Sutter and Andrei Alexandrescu at items 27 and 55 in particular.
>
> If operators returns const objects the many functions should probably
> also returns const objects.
>
> As mentionned in the book, returning const objects disable some
> usefull construct on temporary objects (like calling a non-const
> member function) and might break some existing client code.
>
> So for consistency, I think that boost operators should returns
> non-const objects as most librairies do (including probably the
> STL for complex numbers).

It was discussed in the past IIRC and Philippe's rationale basically
captures the consensus here.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk