Boost logo

Boost :

Subject: Re: [boost] [operators] A modern SFINAE-based version of boost::operators?
From: Edward Diener (eldiener_at_[hidden])
Date: 2017-11-14 21:32:09


On 11/14/2017 2:35 PM, Daniel Frey via Boost wrote:
>> My understanding may be deficient but I would never assume that adding two values would change either of the values in any way, even if one or more of those values were rvalue references. Please tell me what I am missing and I will gladly admit my C++ ignorance in this matter if that is the case.
>
> If you pass in an rvalue reference, you *do* expect it to be modified and you do not expect it to be accessible afterwards.

OK, Point conceded.

> Given:
>
> void f( std::vector<int>&& v ) { ... }
>
> and calling
>
> std::vector< int > v = ...;
> f(v);

I think you meant

f(std::move(v));

>
> why do you expect that v has not been changed or that you can still use it?

Agreed.

>
> Even "adding" the values doesn't change that. If you give me an rvalue reference, I'm (mostly) free to destroy it in any way I like :)

Ok. It does seem odd to "change" a value passed in an addition, but I do
see that changing an rvalue reference should be allowable, since it is a
temporary.

>
> And yes, in a moved-from state you are still allowed to re-assign the value. So, I think I am expecting users of those operators (taocpp/operators) to use value-semantics from a user's perspective. You don't write
>
> int r = std::move(1) + std::move(2); just because you don't need 1 and 2 afterwards.

Agreed.


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