Boost logo

Boost :

Subject: Re: [boost] rvalue ref best practices?
From: Olaf van der Spek (ml_at_[hidden])
Date: 2012-06-11 07:25:08


On Mon, Jun 11, 2012 at 1:22 PM, Mathias Gaunard
<mathias.gaunard_at_[hidden]> wrote:
> 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_) {}
> };

Shouldn't you use std::move here to ensure t_ is moved into t (if possible)?

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

-- 
Olaf

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