Boost logo

Boost :

From: Doug Gregor (dgregor_at_[hidden])
Date: 2004-07-22 09:44:39


On Jul 22, 2004, at 8:08 AM, Arkadiy Vertleyb wrote:

> Giovanni Bajo wrote:
>
>> Arkadiy Vertleyb wrote:
>>
>>> One more addition to the typeof library is a macro, that, unlike
>>> BOOST_TYPEOF(), which removes top-level consts and references,
>>> attempts to be closer to the decltype, by preserving lvalue-ness of
>>> its argument:
>>>
>>> BOOST_TYPEOF_PRESERVE_LVALUE(expr)
>>>
>>> I do admit that the name is quite clumzy :(
>>
>> BOOST_DECLTYPE?
>
> Well, unfortunately, it's not exactly decltype :(
>
> In particular:
>
> int i;
> const int ci = 0;
>
> decltype BOOST_TYPEOF_PRESERVE_LVALUE
> -------- ----------------------------
> i int int&
> ci const int const int&
>
> etc.
>
> It is calculated by binding a T& to the expression. If it can't be
> bound the
> type is the same as one returned by BOOST_TYPEOF. If it can, it's
> either
> reference or const reference, depending on the constness of T.

First of all, this is really cool. My initial reaction to the typeof
lib was "cool, we have typeof" but "darn, I can't use it for
result_of". Whatever we name this macro, it's directly usable for
result_of. That's great!

As for naming:

It could just be called BOOST_DECLTYPE, with the caveat that it doesn't
act quite perfectly for variables. Frankly, I couldn't care much less
about variables: you rarely need the type of those, although I could
easily contrive cases.

BOOST_LVALUE_TYPEOF might be the most obvious name: it returns a
reference if it gets an lvalue, a non-reference otherwise.

        Doug


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