Boost logo

Boost :

Subject: Re: [boost] [operators] The future
From: GMan (gmannickg_at_[hidden])
Date: 2011-10-04 18:01:02


On Tue, Oct 4, 2011 at 8:38 AM, Matt Calabrese <rivorus_at_[hidden]> wrote:

> type operator +( type const&, type const& ) or an equivalent with copies is
> defined automatically as normal
>
> type operator +( type&&, type const& ) is defined to use += on the first
> argument which is then move-returned
>
> type operator +( type const& left, type&& right ) is defined as return
> std::move( right ) + left
>
> type operator +( type&& left, type&& right ) required for disambiguation
> and
> just returns std::move( left ) + right
>

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.

-- 
GMan, Nick Gorski

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