|
Boost : |
Subject: [boost] [preprocessor] check if a token is a keyword (was "BOOST_PP_IS_UNARY()")
From: Lorenzo Caminiti (lorcaminiti_at_[hidden])
Date: 2010-08-13 10:52:52
Hello all,
I asked this question before but received no answer: Is there any
problem in using `BOOST_PP_UNARY()` to check if a token matches a
predefined keyword as indicated by the code below?
The following `IS_PUBLIC(token)` macro expands to 1 if `token` is
`public`, to 0 otherwise:
#define PUBLIC_public (1)
#define IS_PUBLIC(token) BOOST_PP_IS_UNARY(BOOST_PP_CAT(PUBLIC_, token))
IS_PUBLIC(public) // Expand to 1.
IS_PUBLIC(abc) // Expand to 0.
This works just fine on both GCC and MSVC. However, `BOOST_PP_UNARY()`
is only part of Boost.Preprocessor private API because:
Paul Mensonides mentioned in
http://lists.boost.org/Archives/boost/2004/08/70238.php
> Paul Mensonides wrote:
> I know. They (and other types of detection macros) are very useful. Right now,
> the Borland configuration is used by the IBM preprocessor and the Sun
> preprocessor also. I'd like to know whether or not those macro definitions work
> correctly on those preprocessors before I add it. Though those macros aren't
> part of the public interface, they are part of the internal interface. I.e.
> they are used internally as if they were a public interface (though they are
> used carefully on some preprocessors). They are stable, and the worst thing
> that might happen in the future is that they will be moved to a different
> directory. Thus, you can use them, but beware of VC and versions of MWCW prior
> to v9. They in particular have severe problems with expansion order. E.g. VC
> will even fail this test:
(Boost.Preprocessor, Boost.Typeof, and Boost.Spirit already use
`BOOST_PP_UNARY()` internally.)
Thank you very much.
-- Lorenzo
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk