Boost logo

Boost Users :

Subject: Re: [Boost-users] BOOST_PP_REPEAT to repeat comma-containing text
From: niXman (i.nixman_at_[hidden])
Date: 2014-04-08 08:52:27


Igor R писал 2014-04-08 16:25:
> Hello,
>
> I'm trying to repeat a group of actual parameters (passed to some 3d
> party plain-C "variadic" function).
> The function call looks like this:
>
> func(count,
> param1, param2, arr1[0], arr2[0],
> param1, param2, arr1[1], arr2[1],
> param1, param2, arr1[2], arr2[2] /* etc */);
>
> So essentially, I'd like to repeat (param1, param2, arr1[n], arr2[n])
> group.
> What is the right way to invoke BOOST_PP_REPEAT in this case?

Hi,

example:

#include <boost/preprocessor/arithmetic/add.hpp>
#include <boost/preprocessor/arithmetic/sub.hpp>
#include <boost/preprocessor/repetition/repeat.hpp>

#define PP_PROC(unused1, idx, from) \
        param1, param2, arr1[BOOST_PP_ADD(from, idx)], arr2[BOOST_PP_ADD(from,
idx)],

#define MY_REPEAT(from, to) \
        BOOST_PP_REPEAT( \
                 BOOST_PP_SUB(to, from) \
                ,PP_PROC \
                ,from \
        )

/* example */
MY_REPEAT(1, 3);
MY_REPEAT(9, 15);

output:
param1, param2, arr1[1], arr2[1],
param1, param2, arr1[2], arr2[2],;

param1, param2, arr1[9], arr2[9],
param1, param2, arr1[10], arr2[10],
param1, param2, arr1[11], arr2[11],
param1, param2, arr1[12], arr2[12],
param1, param2, arr1[13], arr2[13],
param1, param2, arr1[14], arr2[14],;

-- 
Regards, niXman
___________________________________________________
Dual-target(32 & 64-bit) MinGW-W64 compilers for 32 and 64-bit Windows:
http://sourceforge.net/projects/mingw-w64/
___________________________________________________
Another online IDE: http://liveworkspace.org/

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