Boost logo

Boost Users :

Subject: Re: [Boost-users] [preprocessor] variable repetition
From: Manfred Doudar (manfred.doudar_at_[hidden])
Date: 2010-05-31 06:59:26


Hello,

I find I am still far from a solution to this, and hope someone might
kindly chime in. At the _bottom_ of this email is what I've got so far,
though falls short of a solution... help is still sorely needed.

> Not having a good time with the PP lately, and am struggling over the
> following - would like to generate:
>
>
> void foo(T1)
> {
> bar<T1>(a[0]);
> }
>
> void foo(T1, T2)
> {
> bar<T1, T2>(a[0]);
> bar<T1, T2>(a[1]);
> }
>
> void foo(T1, T2, T3)
> {
> bar<T1, T2, T3>(a[0]);
> bar<T1, T2, T3>(a[1]);
> bar<T1, T2, T3>(a[2]);
> }
>
> ...and so on.

I have this far:

#define <boost/preprocessor/iteration/local.hpp>
#define <boost/preprocessor/iteration.hpp>
#define <boost/preprocessor/repetition.hpp>
#define <boost/preprocessor/repetition/enum.hpp>
#define <boost/preprocessor/repetition/enum_params.hpp>
#define <boost/preprocessor/repetition/repeat.h>

#define PASTE(z, n, T) T ## n
/**/

#define MACRO(z, n, T) bar<BOOST_PP_REPEAT(n, PASTE, T)> (a[n]);
/**/

#define INIT(z, n, T) BOOST_PP_REPEAT(1, MACRO, T)
/**/

#define OP2(z, n, T) \
                                                   \
    void foo(BOOST_PP_ENUM_PARAMSi(n, T)) \
    { \
        BOOST_PP_REPEAT(n, INIT, T) \
    }
    /**/

#define OPERATOR(z, n, _) OP2(z, n, T)

#define BOOST_PP_LOCAL_MACRO(n) OPERATOR(_, n, _)
#define BOOST_PP_LOCAL_LIMITS(1, 3)
#include BOOST_PP_LOCAL_ITERATE()
#undef BOOST_PP_LOCAL_MACRO
#undef BOOST_PP_LOCAL_LIMITS
#undef OPERATOR

The above almost gives what I am after, **but fails**; resulting output
is:

   void foo(T0)
   {
        bar< >(a[0]);
   }
   void foo(T1, T2)
   {
        bar< >(a[0]);
        bar< >(a[0]);
   }
   void foo(T1, T2, T3)
   {
        bar< >(a[0]);
        bar< >(a[0]);
        bar< >(a[0]);
   }

-template parameters on 'bar' are still lacking
-varying index on 'a' also lacking

..Sincerely hoping a kind soul might point out what in the above needs
changing to achieve desired result.

--
Manfred

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net