Boost logo

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:


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,
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 (or Spirit
repository, TYPEOF_DEV branch).

As always any comments are welcome.


Boost list run by bdawes at, gregod at, cpdaniel at, john at