Boost logo

Boost :

Subject: Re: [boost] [operators] The future
From: Nevin Liber (nevin_at_[hidden])
Date: 2011-10-04 18:50:41


On 4 October 2011 17:38, Matt Calabrese <rivorus_at_[hidden]> wrote:
> On Tue, Oct 4, 2011 at 6:01 PM, GMan <gmannickg_at_[hidden]> wrote:
>>
>> If we're going for C++11, I think the correct way to do this is with a
>> single function:
>>
>> type operator+(type lhs, const type& rhs)
>> {
>>    lhs += rhs;
>>    return lhs;
>> }
>>
>> That should, given that the class implements move-semantics, be sufficient.
>
>
> If you do that then what does the version look like if the right hand
> operand is the moved-from operand? If you do:
>
> type operator+( const type& lhs, type rhs ) { /*...*/ }

You are assuming that the user intends operator+ to be commutative.
The user will need some way to specify it as they can if the type of
lhs and rhs are different, and if that assumption is the default, it
may break existing code.

-- 
 Nevin ":-)" Liber  <mailto:nevin_at_[hidden]>  (847) 691-1404

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