Boost logo

Boost :

From: Eric Niebler (eric_at_[hidden])
Date: 2008-07-02 18:34:29


Joel de Guzman wrote:
> Eric Niebler wrote:
>> BOOST_TYPEOF can't perfectly distinguish between lvalues and
>> rvalues.
>
> Yeah, that's my basic problem with BOOST_TYPEOF.
>
>> I fudge it where I have to,
>
> Where do you fudge it? if_then expression? How? How about ordinary
> operators like a + b? Do you simply not allow weird uses like:
>
> X& operator+(A a, B b)
>
> return a reference??

I use BOOST_TYPEOF to get the type of an expression. Then, I check to
see if the expression can bind to a non-const reference using the sizeof
trick. If it does, then I treat the result as an lvalue and add a
reference to the expression's type. It gets the answer wrong for
const-qualified rvalues, but in the above example, it would correctly
deduce the type of "A()+B()" to be "X&".

-- 
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