
On 29.08.2011 14:41, Szymon Gatner wrote:
2011/8/29 Martin B.<0xCDCDCDCD@gmx.at>:
On 26.08.2011 20:21, Ovanes Markarian wrote:
On Fri, Aug 26, 2011 at 2:30 PM, Martin B.<0xCDCDCDCD@gmx.at mailto:0xCDCDCDCD@gmx.at> wrote:
Hi!
Say I have a range R and I want to construct a new container from the range R. Will I always have to repeat the expression yielding the range, or is there a shorter way?
I do something like this:
... { ... v(boost::begin(rng), boost::end(rng));
return move(v); }
and using it surprisingly often as move semantics allow for cheap return-by-value
That code is wrong. (As far as I understand C++11.) AFAIK, you should *never*(?) explicitly move the return value as: * The compiler is free to do so anyway. (AFAIK) * It will prevent RVO. (AFAIK) so I would just leave the move and do a `return v;` relying on the fact that even my C++03 my compiler will do RVO and in-place construction of the returned vector anyway. cheers, Martin