Boost logo

Boost :

Subject: Re: [boost] [proto] RValue reference support?
From: Eric Niebler (eric_at_[hidden])
Date: 2011-08-11 12:52:07


On 8/11/2011 8:19 AM, John Maddock wrote:
>> No, unfortunately.
>> I think Eric said that for C++0x, it would be nice to rewrite a lot of
>> things to make them simpler and faster to compile.
>>
>> I think it would be a useful addition in the current Proto without
>> re-writing all of it though.
>>
>> I suspect however that if you don't rely on the default operator
>> overloads and call make_expr yourself, it might work.
>>
>>
>>> I'm thinking that if you know that you're assigning an expression
>>> involving an rvalue-reference as a terminal, then there are some
>>> optimizations that can be performed that aren't otherwise possible.
>>
>> Do you have an example of a DSL where that would be useful?
>
> Well actually.... now I come to think of it some more, I'm not sure it's
> as useful as I first thought: a nice "luxury feature" maybe, but not
> essential.
>
> The example is the archetypical "big number" class - the idea is to
> minimize the number of temporaries created while evaluating an
> expression - not just removing "return by value from operator" that
> expression templates provide by default, but to analyze the expression,
> figure out a [semi-]optimal evaluation order and reuse temporaries as
> far as is possible.
>
> But I'm figuring that the occurrence of temporaries on the RHS of an
> expression, while not out of the question, is rare enough not to be too
> concerned about.

You can use Proto to eliminate the need for temporaries without rvalue
reference support. What you describe above is a textbook application of
expression templates. If it will save you 1 dynamic allocation every now
and then, it's probably worth considering.

Can you explain again why rvalue references are important for you? I'm
not following.

-- 
Eric Niebler
BoostPro Computing
http://www.boostpro.com

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