Boost logo

Boost :

From: Paul Mensonides (pmenso57_at_[hidden])
Date: 2005-03-22 04:48:11


> -----Original Message-----
> From: boost-bounces_at_[hidden]
> [mailto:boost-bounces_at_[hidden]] On Behalf Of Edward Bishop

> >> The IS_UNSIGNED_CHAR() macro is meant to be used in another macro:
> >>
> >> #define IS_BUILTIN_TYPE(x) BOOST_PP_OR(IS_UNSIGNED_CHAR(x), ...
> >
> >
> > But wouldn't it be more appropriate to do that at the type level so
> > you can take into account typedefs?
> >
>
> Yes, but for the challange and the learning experience I'm
> trying to do it just using the preprocessor.

I was about to say the same thing as Andrei, but I didn't have time to get back
to it yet. The preprocessor is good a certain things. Type manipulation is not
one of them. Templates are much better at that. However, the preprocessor is
good at (for example) generating instances of a patterns over a set of types.
An 'is-builtin-type' predicate as a macro raises flags. It is one thing to
generate, e.g., template specializations that together act as an
'is-builtin-type' facility. Doing so increases the level of abstraction by
making a code pattern explicit. Doing actual type manipulation is fraught with
problems and is almost always better done with core language features. As
Andrei mentions, typedefs introduce a problem (lack of extensibility).
Similarly (for something like the above), you have to handle all possible
synonyms resulting from combinations (e.g. unsigned char == char unsigned).

I recognize the desire to learn how to use the preprocessor, but part of that is
learning where the use of the preprocessor is better and when it isn't.

For the sake of argument, say you're going to do the above just for fun or as a
learning tool. The approach that I described doesn't scale (even to just the
built-in types). The code required would be so bloated that it would be easier
to manually write a bunch of template specializations. If you were going to do
something like this generally, a better approach would be to split words into
single characters and compare strings of characters.

Regards,
Paul Mensonides


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