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++

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

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

> 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,
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

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

John R. Bandela

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