From: Arkadiy Vertleyb (vertleyb_at_[hidden])
Date: 2004-08-27 01:00:35


"Paul Mensonides" <pmenso57_at_[hidden]> wrote

> It isn't usually the case that preprocessor metaprogramming is used to do
type
> computation. It is possible, of course, given enough scaffolding, but
templates
> are much more naturally suited to it. Types as values just doesn't scale
with
> the preprocessor. It is common, OTOH, to generate a template-based
solution
> with the preprocessor. Thus, what exactly are you trying to do?

I am trying to extend my typeof emulation system (see
http://groups.yahoo.com/group/boost/files/typeof.zip) with the ability to
conveniently support integral template parameters. I am generating partial
template specializations that are responsible for encoding/decoding of a
template instantiation. In such specialization, type parameters are handled
differently from integral parameters in a few different aspects. I could
encapsulate these aspects in a preprocessor tuple, and provide macros to
generate these tuples, so that I would get something like this from the
user:

template<typename T, bool b, unsigned int n> class foo;

REGISTER_TEMPLATE(foo, 3, (
    TYPE_ARG,
    INTEGRAL_ARG(bool),
    INTEGRAL_ARG(unsigned int)
)); // this expands into encoding/decoding specializations

Here both TYPE_ARG and INTEGRAL_ARG(x) expand into a preprocessor tuple
where all the necessary information is contained, so that I can generate my
specializations.

This looks implementable, but I am just trying to explore an alternative,
where the user would just specify:

REGISTER_TEMPLATE(foo, 3, (typename, bool, unsigned int));

And this requires to associate a few properties with, e.g., "unsigned int",
which caused my original question.

> > So I am wonderring if there is any facility in the
> > preprocessor (or in the
> > Boost.Preprocessor) that would allow me to do this.
>
> There isn't a facility to do it directly in the pp-lib, but it is
possible.

Any information on the subject would be greatly appreciated.

Thanks,
Arkadiy