|
Boost : |
From: Daniel James (daniel_at_[hidden])
Date: 2004-07-31 08:50:46
I've ported the preprocessor library to the Digital Mars preprocessor. The
patch is at:
http://myweb.tiscali.co.uk/calamity/patches/preprocessor-1.patch.gz
With it, the only test which doesn't pass is the BOOST_PP_LINE test in
debug.cpp, because the preprocessor has problems with macro expansion in
#line statements.
Would it be possible to add this to CVS after the release? Unless I've
made a mistake, it won't interfere with any other preprocessors.
The patch works around two bugs in the preprocessor. First, in a statement
like this:
#define FOO(pred, x) BAR(pred(x))
pred(x) won't get expanded. There are several ways to work around this,
the one I've mostly used is to write:
#define FOO(pred, x) BAR(pred##(x))
You can also use:
#define CALL(pred, x) pred(x)
#define FOO(pred, x) BAR(CALL(pred, x))
And, with the patch:
#define FOO(pred, x) BAR(BOOST_PP_EXPAND(pred(x)))
But, I think those two could cause problems with recursion.
The other bug is with the preprocessors handling of whitespace. In the
following example, neither concatenations work, both give '1 1' instead of
'11'.
#define EMPTY
#define TRAILING_WHITESPACE(x) x EMPTY
#define LEADING_WHITESPACE(x) EMPTY x
BOOST_PP_CAT(TRAILING_WHITESPACE(1), 1)
BOOST_PP_CAT(1, LEADING_WHITESPACE(1))
This causes subtle bugs with macros like this:
#define BOOST_PP_LESS(x, y) BOOST_PP_IIF( \
BOOST_PP_NOT_EQUAL(x, y), \
BOOST_PP_LESS_EQUAL, 0 BOOST_PP_TUPLE_EAT_2)(x, y)
This leaves a white space after the 0 when x and y are equal which
prevents concatenation. This is mainly a problem with BOOST_PP_WHILE,
BOOST_PP_FOLD_LEFT etc.
It is possible to remove the whitespace by concatenating it to a macro
which expands to nothing, but that is only possible when you know that
there is definitely going to be whitespace.
thanks,
Daniel
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk