$include_dir="/home/hyper-archives/boost/include"; include("$include_dir/msg-header.inc") ?>
From: Darren Cook (darren_at_[hidden])
Date: 2003-10-16 04:28:14
Hi Paul,
I'm trying to use your example code now, and also to understand it, so I've 
got a few questions.
  1. For "#define params(z, n, _)" is "_" a convention meaning a parameter 
that is not used? Is 'z' being used behind the scenese somewhere, or could I 
also write:
    #define params(_, n, _)
or
    #define params(_1, n, _2)
2. What is the meaning of "~" here:
    void func(BOOST_PP_ENUM(arity, params, ~))
   I couldn't see this used in any of the examples, nor mentioned in 
BOOST_PP_ENUM reference page.
Thanks,
Darren
> Hi Darren, the following implements the overloads up to ARITY pairs of
> parameters:
> 
> #include <boost/preprocessor/cat.hpp>
> #include <boost/preprocessor/iteration/local.hpp>
> #include <boost/preprocessor/repetition/enum.hpp>
> #include <boost/preprocessor/repetition/repeat.hpp>
> 
> #define ARITY 3
> 
> class some_class {
>     public:
>         void add_ifthere(int d, int v) { /**/ }
>         void add_normal(int d, int v) { /**/ }
>         void add_only(int d, int v) { /**/ }
> 
>         // generates n-th parameter pair, as in:
>         //    int d0, int v0
> 
>         #define params(z, n, _) \
>             int BOOST_PP_CAT(d, n), int BOOST_PP_CAT(v, n) \
>             /**/
> 
>         // generates the n-th call to "func", as in:
>         //    add_ifthere(d0, v0);
> 
>         #define call(z, n, func) \
>             func(BOOST_PP_CAT(d, n), BOOST_PP_CAT(v, n)); \
>             /**/
> 
>         // generates a function definition of "func"
>         // with "arity" parameter pairs, as in:
>         //    void add_ifthere(int d0, int v0, int d1, int v1) {
>         //        add_ifthere(d0, v0);
>         //        add_ifthere(d1, v1);
>         //    }
> 
>         #define make_function(arity, func) \
>             void func(BOOST_PP_ENUM(arity, params, ~)) { \
>                 BOOST_PP_REPEAT(arity, call, func); \
>             } \
>             /**/
> 
>         // [macro repeated by local iteration]
>         // makes a copy of each function for logical arity n
> 
>         #define BOOST_PP_LOCAL_MACRO(n) \
>             make_function(n, add_ifthere) \
>             make_function(n, add_normal) \
>             make_function(n, add_only) \
>             /**/
> 
>         // [boundaries of local iteration]
> 
>         #define BOOST_PP_LOCAL_LIMITS \
>             (2, (ARITY) < 2 ? 2 : (ARITY)) \
>             /**/
> 
>         // repeat BOOST_PP_LOCAL_MACRO with 'n' ranging
>         // from 2 to ARITY
> 
>         #include BOOST_PP_LOCAL_ITERATE()
> 
>         // undefine temporary macros
>         // (BOOST_PP_ macros are automatically undefined)
> 
>         #undef params
>         #undef call
>         #undef make_function
> };
> 
> Regards,
> Paul Mensonides
> 
> _______________________________________________
> Unsubscribe & other changes: http://listarchives.boost.org/mailman/listinfo.cgi/boost
>