|
Boost : |
Subject: Re: [boost] rvalue ref best practices?
From: Mathias Gaunard (mathias.gaunard_at_[hidden])
Date: 2012-06-11 07:22:01
On 11/06/2012 13:14, Giovanni Piero Deretta wrote:
> Apart from the fact that "an arbitrary place" in your sentence would
> seem to cover anything
You don't get to choose where. The compiler does.
> to what subobject are you referring to?
Any subobject. Or any specific storage really.
> The
> only thing I can think of is assignment operators of derived classes
> that need to forward to base classes. In that case I agree that pass
> by value does not work very well (I usually still use pass by value,
> but implement operator= in term of swap, which forwards to the base
> class swap).
According to this rule, I should pass by value whenever I want to copy
the variable anyway.
template<class T>
struct foo
{
T t;
foo(T t_) : t(t_) {}
};
Clearly we can see this code causes one copy with rvalues, two with
lvalues, instead of always one if we used const-reference.
The only instance where this might be useful is operator=, and then
again, it's probably still a bad idea.
I had already pointed out to Dave that the way the rule as worded was
incorrect.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk