$include_dir="/home/hyper-archives/boost/include"; include("$include_dir/msg-header.inc") ?>
From: Paul Mensonides (pmenso57_at_[hidden])
Date: 2003-04-11 16:43:41
Aleksey Gurtovoy wrote:
>> First, though, I want to make sure I understand exactly what you
>> mean. Do you want everything to automatically pick up the default
>> value(s)? Or do you just want a way to signal "use default" to the
>> implementation of the macro in question, such as "MY_MACRO" above?
>
> The latter. Basically, I want something like this (pseudo code):
>
> #define MY_MACRO(n, func) \
> BOOST_PP_IF( \
> BOOST_PP_TOKEN_EQUAL(func, default) \
> , DO_SOMETHING \
> , DO_SOMETHING_WITH_DEFAULT_FUNC \
> )(n) \
> /**/
Without, once again, token-pasting of unrelated tokens, I cannot do this for
_arbitrary_ input. However, I can under certain constraints. If 'func' is +, I
cannot compare it to "default". If func is MY_MACRO, then I can. If you make
the following input constraint: Input is not allowed to be parenthesized, then
you can do it like this:
#define MY_MACRO(n, func) \
IF( \
IS_UNARY(func), \
DO_SOMETHING, \
DO_SOMETHING_WITH_DEFAULT_FUNC \
)(n) \
/**/
Of course, you'd presumably want to actually *use* func for something. Plus,
the above isn't the "best" solution. E.g. this is better:
#define DEFAULT(x, def) \
IIF( \
IS_UNARY(x), \
x,
def \
) \
/**/
#define MACRO(n, func) \
DEFAULT(func, DEFAULT_FUNC)(n) \
/**/
#define DEFAULT_FUNC(n) default
#define FUNC(n) user
MACRO(5, FUNC) // user
MACRO(5, (*) ) // default
P.S. it doesn't matter what is inside the unary parentheses. It could be
(default) or whatever else you might want.
Paul Mensonides