|
Boost : |
Subject: Re: [boost] [proto] RValue reference support?
From: Mathias Gaunard (mathias.gaunard_at_[hidden])
Date: 2011-08-11 16:38:45
On 08/11/2011 08:55 PM, Eric Niebler wrote:
> Consider how it
> works for vectors. You want to evaluate the expression as:
>
> tmp1 = foo();
> tmp2 = vector of right size
> for (int i in 0 to tmp2.size()-1)
> tmp2[i] = x[i]*y[i]+tmp1[i]*z[i];
> swap(a, tmp2);
or
tmp1 = foo()
a.resize(the_right_size)
for (int i in 0 to a.size()-1)
a[i] = x[i]*y[i]+tmp1[i]*z[i];
This avoids an unnecessary allocation if a is already of the right size.
It's not strongly exception-safe, though.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk