Boost logo

Boost :

From: Aleksey Gurtovoy (agurtovoy_at_[hidden])
Date: 2003-04-11 16:28:27


Paul Mensonides wrote:
> 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?
>
> It depends. There isn't a completely general way of doing this
> without "token-pasting unrelated-tokens" being well-defined.
> However, it can be done if you formalize it as a set of conventions.
>
> 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) \
/**/

Aleksey


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk