Boost logo

Boost :

From: jbandela_at_[hidden]
Date: 2001-06-07 10:13:13


> 1. Is TYPEOF a macro?
Yes, it is. The macro expands to something like
TypeOfHelper</*bunch of stuff*/>::Type

> 2. How does it conform to GCC's and CodeWarrior's typeof
> and the typeof that is currently being proposed as a new C++
keyword?

It takes an expression, and generates a type. The type can then be
used to typedef or declare a variable. I believe this is how typeof
will also work.

> 3. How portable is it? Does it compile on different
compilers/platforms?

To the best of my knowledge it is fully standard c++, and should
commpile on any standard conforming compiler. It does not compile on
VC++ or BC++ because they lack template template parameters. It
should compile on any compiler that supports partial specialization
and template-template parameters.
However, the only compiler I have access to that supports these
features is gcc. I believe Comeau C++ and CodeWarrior also support
these features. If someone could test with those I would appreciate
it.

> 4. How is it much better than other typeof implementations?

I believe this is the best typeof this side of a compiler
implementations. The big feature is that once you register a template
or class, you can use any valid combination of those types and const,
volatile, and pointers. For example JRB_TYPE0(int) allows you to use
int, const int, volatile int, const volatile int, int*, int**,
int******, const int*, int * const, etc. Say you have a class
MyTemplate that takes 1 type,
JRB_TYPE0(int)
JRB_TYPE1(MyTemplate)
allows you to use MyTemplate<int>, MyTemplate<int***>,
MyTemplate<MyTemplate<MyTemplate<int***> > > etc.

All the other non-compiler implementations I am aware of require you
register the exact type. For example, to use int and int*, you would
have to register both they types. Also with the previous example, to
use MyTemplate<int> and MyTemplate<MyTemplate<int> > you would have
to register them both explictly.

I think this capability is important for expression template
libraries like Spirit. Those kind of libraries, use say around 50
templates or classes along with the primities, to generate basically
an infinite amount of types. Registering all 50 or so types, allows
us to use TYPEOF with basically any valid expression using the
library. Other typeofs would be useless, since the exact type would
have to be registered, and the exact type is usually unique to an
expression.

> 5. Where can I find your code?
In the TYPEOF directory of Boost files

Cheers,
John R. Bandela


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