Subject: Re: [boost] rvalue ref best practices?
From: Ion GaztaÃ±aga (igaztanaga_at_[hidden])
Date: 2012-06-12 17:31:58
El 12/06/2012 16:51, Mathias Gaunard escribiÃ³:
> On 06/11/2012 09:21 PM, Ion GaztaÃ±aga wrote:
>> If it's going to be assigned, I want to reuse a's
> And that's the problem. Reusing those resources is destructive, so if
> your function fails before it returns the new value, the old value is lost.
> It is not natural for something written as foo = bar(); to change foo if
> bar fails.
Thanks for pointing this, I was completely missing it. If the assignment
syntax is confusing then the only choice not to surprise the programmer
is to use reference passing syntax. Since we all agree that
means that a could be left in an indeterminate state. Then the question
is how can we make this optimal also with non-constructed objects.
1) Some NRVO, some modified
//NRVO for a&c, mutable reference for b&d
[A a, C c] -> modify_or_construct(a, b, c, d);
2) All modified
modify_or_construct(a, b, c, d);
3) All constructed via NRVO to obtain strong exception guarantee (assume
A, B, C, D's move constructors don't throw)
[A a2, B b2, C c2, D d2] -> modify_or_construct(a, b, c, d);
a = std::move(a2);
b = std::move(b2);
c = std::move(c2);
d = std::move(d2);
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk