
11 Aug
2011
11 Aug
'11
8:38 p.m.
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.