|
Boost : |
From: Paul Mensonides (pmenso57_at_[hidden])
Date: 2003-04-11 16:17:36
Aleksey Gurtovoy wrote:
> Is there a way to detect a particular pre-defined token passed as a
> parameter to a macro? If yes, can we fold it into a PP-library
> primitive so one can reuse it easily?
>
> For instance, I would like to be able to allow both this:
>
> MY_MACRO(10, MY_OTHER_MACRO)
>
> and this:
>
> MY_MACRO(10, default) // use the "default parameter"
>
> Is there a known way to implement it?
BTW, it is easy to compare identifiers/keywords provided that you have 1) a
strict preprocessor, and 2) a simple "traits" macro for each identifier that you
might want to compare. For example, if you want to be able to compare
identifiers for "Aleksey" and "Paul," you need these to macros (abbreviating
macro prefix to "_" for brevity):
// general macro:
#define _COMPARE(a, b) \
_IIF( \
_BITAND( \
_IS_NULLARY( _CAT(_, a)(()) ), \
_IS_NULLARY( _CAT(_, b)(()) ) \
), \
_COMPARE_I, \
0 _TUPLE_EAT(2) \
)(a, b) \
/**/
#define _COMPARE_I(a, b) \
_COMPL(_IS_NULLARY( \
_COMPARE_ ## a( \
_COMPARE_ ## b \
)(()) \
)) \
/**/
// custom user-defined macros:
#define _COMPARE_Aleksey(x) x
#define _COMPARE_Paul(x) x
_COMPARE(abc, Aleksey) // 0
_COMPARE(Paul, Aleksey) // 0
_COMPARE(Aleksey, abc) // 0
_COMPARE(Aleksey, Aleksey) // 1
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