|
Boost : |
From: Andrei Alexandrescu (andrewalex_at_[hidden])
Date: 2001-11-20 02:04:55
> Yes, but WHY A MACRO?
Ok, I agree in this case one can use super_subclass<T, U>::type (can you say
"pretty ugly")...
> Much as I admire your code in general, Andrei, you do have this
> deplorable tendency to fall in love with the preprocessor. :-) There are
> several concepts in MC++D (TYPELIST<n> is another) that, for no good
> reason that I can see, you've gratuitously written as macros when they
> could be expressed just as easily in safe code.
You must be referring to the TYPELIST_nn macros.
It's very simple. I don't give a rat's ass on the preprocessor and I'm fully
aware of its vandalism. It's just that the set of requirements that I had
for typelist "constructors" left the preprocessor as the only contender:
1. easy to use
2. scaleable up to more parameters
(We can discuss separately whether or not these were good criteria.)
So I put together the nasty TYPELIST_1 to TYPELIST_50 and used them. I
didn't notice name clashes etc., but I did notice an important shortcoming:
3. If you use a comma inside a macro, it won't work. Consider:
typedef TYPELIST_2(vector<int, myallocator>, vector<int, yourallocator>)
TwoVectors;
that won't work because the preprocessor strongly believes that you actually
passed four arguments to TYPELIST_2. What a nuisance. You can fix that by
putting in place typedefs for those types.
So it's a tradeoff issue. Any solution that fixes point 3 fails on point 1,
point 2, or (most often) both 1 and 2.
Andrei
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk