Boost logo

Boost Users :

Subject: [Boost-users] BOOT_PP_REPEAT simple nesting problem
From: Colin Fowler (fowler_at_[hidden])
Date: 2014-09-20 09:35:32


Hi all, I'm trying to use BOOST_PP to generate some code.

I can generate the sequence int x_0 to int x_4 using the code below.

#include <boost/preprocessor/repetition/repeat.hpp>
#define DECL1(z, n, text) text ## _ ## n = n;
#define decl1(text, count) BOOST_PP_REPEAT(count, DECL1, text)
decl1 (int x, 5)

What I'd like to do is write a decl2 that can be used something like
this:

decl2 (int x, 5, 2)

to generate int x_0_0 to int x_4_1

I've tried nesting BOOST_PP_REPEAT but so far I've been unable to
produce the desired behaviour unless I hardcode one of the iteration
counts.

I'd like to also eventually write a decl3(int x, 5, 3, 4) when I
understand how a decl2 would work. Any help much appreciated!

Regards,
         Colin


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