Boost logo

Boost :

From: Paul Mensonides (pmenso57_at_[hidden])
Date: 2005-03-19 19:11:11


> -----Original Message-----
> From: boost-bounces_at_[hidden]
> [mailto:boost-bounces_at_[hidden]] On Behalf Of Paul Mensonides

> > Any suggestions? Here is the code:
>
> Are you trying to detect 'unsigned char' specifically, or are
> you ultimately trying to compare strings of identifiers
> (keywords are identifiers here)?

Here's a more robust implementation of the former:

#include <boost/preprocessor/cat.hpp>
#include <boost/preprocessor/control/iif.hpp>
#include <boost/preprocessor/detail/is_nullary.hpp>
#include <boost/preprocessor/facilities/empty.hpp>
#include <boost/preprocessor/facilities/expand.hpp>
#include <boost/preprocessor/tuple/eat.hpp>

#define IS_UNSIGNED_CHAR(x) \
    BOOST_PP_IIF( \
        BOOST_PP_IS_NULLARY( \
            BOOST_PP_CAT(UNSIGNED_, x) \
        ), \
        BOOST_PP_IIF( \
            BOOST_PP_IS_NULLARY( \
                BOOST_PP_EXPAND(BOOST_PP_EMPTY BOOST_PP_CAT(UNSIGNED_, x))() \
            ), \
            0 BOOST_PP_TUPLE_EAT(1), IS_UNSIGNED_CHAR_II \
        ), \
        0 BOOST_PP_TUPLE_EAT(1) \
    )(BOOST_PP_EMPTY BOOST_PP_CAT(UNSIGNED_, x)) \
    /**/
#define IS_UNSIGNED_CHAR_II(x) \
    BOOST_PP_IIF( \
        BOOST_PP_IS_NULLARY( \
            BOOST_PP_CAT(CHAR_, x) \
        ), \
        BOOST_PP_IS_NULLARY, 0 BOOST_PP_TUPLE_EAT(1) \
    )(BOOST_PP_EXPAND(BOOST_PP_EMPTY BOOST_PP_CAT(CHAR_, x))()) \
    /**/

#define UNSIGNED_unsigned ()
#define CHAR_char ()

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