Boost logo

Boost :

Subject: Re: [boost] [xint] Third release is ready, requesting preliminary review
From: Jeffrey Lee Hellrung, Jr. (jhellrung_at_[hidden])
Date: 2010-05-04 10:54:00


On 5/4/2010 12:29 AM, DE wrote:
> on 03.05.2010 at 23:55
> vicente.botet wrote :
>> In a post from yesterday it was said that the arithmetic operators
>> were not implemented following move semantics. The signatures were
>> given, but no replay to this post has been done yet. I'm sure that
>> the poster was looking into the sources.
>
> actually i don't see a reason to implement them that way
> rather they should be implemented either of two ways
>
> type operator@(type, const type&);
> type operator#(const type&, const type&);
>
> but not simultaneously
> in the first case move semantics will take place where appropriate

No good :( Assuming only the *possibility* of reusing resources from
your arguments, you want the signature operator+(T,T) if you're adding 2
rvalues, but the signature operator+(const T&, const T&) if you're
adding 2 lvalues (so you don't make unnecessary copies compared to
passing by value). Unfortunately, you can't have both (ambiguous
overload resolution) :/ The only way to get something semantically
equivalent is to overload by rvalue reference.

If reuse of resources is *unconditional*, then, sure, pass by value (as
long as the swapping/moving is cheap). If reuse of resources *never*
happens, then, sure, pass by reference-to-const. Otherwise, the optimal
approach is to provide all combinations of rvalue reference and lvalue
reference-to-const parameters (in c++03).

- Jeff


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