|
Boost : |
From: Vertleyb (vertleyb_at_[hidden])
Date: 2004-07-22 00:02:23
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 :(
It is directly based on the rules of binding a reference. The following
table outlines which types are returned:
Expression lvalue? typeof_preserve_lvalue(expression)
---------- ------- ------
int n; lvalue int&
const int m; lvalue const int&
int& rn = n; lvalue int&
const int& rm; lvalue const int&
int foo1(); int
const int foo2(); const int& (unfortunately, in both
VC7.1 and GCC 3.3)
int& foo3(); lvalue int&
const int& foo4(); lvalue const int&
int(21) int
21 int
The BOOST_AUTO remains based on the BOOST_TYPEOF. The references, in the
same way as proposed in
http://www.osl.iu.edu/~jajarvi/publications/papers/decltype_n1478.pdf,
should be specified explicitly:
int& foo();
BOOST_AUTO(v, foo()); // auto v = foo();
BOOST_AUTO(&r, foo()); // auto& r = foo();
BOOST_AUTO(const& cr, foo()); // auto const& cr = foo();
See http://groups.yahoo.com/group/boost/files/typeof.zip (or Spirit
repository, TYPEOF_DEV branch).
As always any comments are welcome.
Thanks,
Arkadiy
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk