Boost logo

Boost :

Subject: Re: [boost] [operators] A modern SFINAE-based version of boost::operators?
From: Daniel Frey (d.frey_at_[hidden])
Date: 2017-11-14 19:35:20


> 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. Given:

void f( std::vector<int>&& v ) { ... }

and calling

std::vector< int > v = ...;
f(v);

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

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 :)

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.




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