From: Arkadiy Vertleyb (vertleyb_at_[hidden])
Date: 2004-05-02 20:38:36
A couple of weeks ago I initiated the discussion about simple typeof
emulation, and provided an example on how it can be done with the help of
MPL vector of integral constants. I then used MS-specific __COUNTER__ macro
to spare the user from specifying the unique integer for each registered
class/template. I hoped to find a way to do something similar in standard
C++, and asked preprocessor experts for help.
Indeed, Paul Mensonides suggested such a way. At first I thought that it
will not be good enough replacement for the __COUNTER__, but then I realized
that I was wrong. So I re-worked my implementation of typeof, and now
offerring it to your attention.
Besides removing __COUNTER__, I used the Boost.Preprocessor library to
cleanup the implementation. Also, after the discussion with Jody Hagins, I
put the encoding/decoding classes inside anonimous namespace to avoid
collisions between translation units.
The provided example shows what registration needs to be done to calculate
the type of a lambda functor:
BOOST_TYPEOF_ALLOCATE(fun, _1 > 15 && _2 < 20); // <unspecified> fun(_1
> 15 && _2 < 20);
int n = 19;
One of remaining problems is inability to process top-level consts and
references, that get eatten up at the function level, before the partial
template specialization gets involved...
Although I believe that I don't do anything non-standard now, unfortunately
I can't prove it myself. The only compiler I have besides MSVC is GCC, and
it gives me "sorry not implemented" on something as simple as
mpl::int_<sizeof(foo(...))>... Besides, GCC already has a typeof. Would
anybody be so kind as to try the "typeof" with some other compiler? I would
really apprciate this...
Here is the link:
Any comments are greatly appreciated.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk