Boost logo

Boost :

From: Paul Mensonides (pmenso57_at_[hidden])
Date: 2006-02-22 08:18:04


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

> Paul Mensonides wrote:
>
> > For now, C++ doesn't have variadics and placemarkers, so I
> can't add
> > the first one to the Boost Preprocessor library.
>
> I believe they are present in the current working draught for
> C++0x though, so you could add 'experimental' support with a
> C++0x feature detection macro, if you were feeling adventurous ;?)

Well, such a thing would could be categorized as a "technological preview". If
I was going to do that, I'd add Chaos to Boost--though I don't know if Boost is
even interested in that (and even if it is, there are several policy issues that
would have to be addressed).

Regarding future variadic support in the pp-lib... There are a lot of things
that have to change to do this correctly--most of them involve changing argument
orders to best take advantage of variadics (and that is a significant change).

Regarding emptiness detection... This is how Chaos does it (in case anyone is
interested)...

#define CAT(a, ...) PRIMITIVE_CAT(a, __VA_ARGS__)
#define PRIMITIVE_CAT(a, ...) a ## __VA_ARGS__

#define IIF(bit) PRIMITIVE_CAT(IIF_, bit)
  #define IIF_0(t, ...) __VA_ARGS__
  #define IIF_1(t, ...) t

#define SPLIT(i, ...) PRIMITIVE_CAT(SPLIT_, i)(__VA_ARGS__)
  #define SPLIT_0(a, ...) a
  #define SPLIT_1(a, ...) __VA_ARGS__

#define IS_VARIADIC(...) \
    SPLIT(0, CAT(IS_VARIADIC_R_, IS_VARIADIC_C __VA_ARGS__)) \
    /**/
  #define IS_VARIADIC_C(...) 1
  #define IS_VARIADIC_R_1 1,
  #define IS_VARIADIC_R_IS_VARIADIC_C 0,

#define IS_EMPTY_NON_FUNCTION(...) \
    IIF(IS_VARIADIC(__VA_ARGS__))( \
        0, \
        IS_VARIADIC(IS_EMPTY_NON_FUNCTION_C __VA_ARGS__ ()) \
    ) \
    /**/
  #define IS_EMPTY_NON_FUNCTION_C() ()

This will detect all emptiness except that it will fail if the input ends with a
function-like macro name, such as:

#define A() 123

IS_VARIADIC(A)

This sort of thing will either error, or yield unpredictable results.

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