|
Boost : |
From: Howard Hinnant (hinnant_at_[hidden])
Date: 2002-02-04 21:40:17
On Monday, February 4, 2002, at 09:18 PM, Rainer Deyke wrote:
> std::vector<int> g()
> {
> std::vector<int> first, second;
> // Do various operations on 'first' and 'second' here.
> return (first.size() > second.size()) ? first : second;
> }
>
> std::vector<int> v(g());
>
> The compiler can't construct the return value "in place" because it
> does not know which of the two vectors will be returned at the time of
> construction.
>
>
>> But here's another possibility in case your compiler
>> is weak in this area:
>>
>> T b(std::move(f()));
>>
>> (assuming we can get the move from temporary worked out)
>
> I don't think this will work because by the time 'f' returns, the
> temporary will already be copied.
Good example!
How 'bout:
std::vector<int> g()
{
std::vector<int> first, second;
// Do various operations on 'first' and 'second' here.
return std::vector<int>(std::move(first.size() > second.size() ?
first : second));
}
std::vector<int> v(std::move(g()));
?
-Howard
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk