|
Boost Users : |
Subject: Re: [Boost-users] BOOST_PP_ERROR(0x0003, BOOST_PP_REPEAT_OVERFLOW) with multiply nested BOOST_PP_REPEATS
From: pfultz2 (pfultz2_at_[hidden])
Date: 2014-09-26 15:38:07
> Am I hitting a nesting depth limit or something else? Is there a way
> around this? Ideally I want to write a decl5 macro and have successfully
> written a decl1, decl2 and decl3 so far
Ok, the best way seems to generate a sequence of your data:
#define GEN_SEQS_EACH_INNER(z, n, data) (n)
#define GEN_SEQS_EACH(s, data, n) BOOST_PP_REPEAT(n,
GEN_SEQS_EACH_INNER, ~)
#define GEN_SEQS(dims) BOOST_PP_SEQ_TRANSFORM(GEN_SEQS_EACH, ~, dims)
This would take a sequence of each of the max values and generates a
sequence of
sequences. So this:
GEN_SEQS((2)(3))
Expands to:
( (0)(1) ) ( (0)(1)(2) )
Then you can use `BOOST_PP_SEQ_FOR_EACH_PRODUCT` to do the cross product of
each
of the sequences concated together:
#define DECL_EACH(r, product) BOOST_PP_SEQ_CAT((int x)product);
#define DECL(dims) BOOST_PP_SEQ_FOR_EACH_PRODUCT(DECL_EACH,
GEN_SEQS(dims))
However, you may want underscores place between the number so you can use an
intersperse macro like this:
#define INTERSPERSE_EACH(r, data, i, elem) BOOST_PP_IF(i, (data)(elem),
(elem))
#define INTERSPERSE(seq, x) BOOST_PP_SEQ_FOR_EACH_I(INTERSPERSE_EACH, x,
seq)
#define DECL_EACH(r, product) BOOST_PP_SEQ_CAT(INTERSPERSE((int
x)product, _));
#define DECL(dims) BOOST_PP_SEQ_FOR_EACH_PRODUCT(DECL_EACH,
GEN_SEQS(dims))
And then you can call it like this:
DECL((2)(2)(2)(2)(2))
Which will generate this:
int x_0_0_0_0_0;
int x_0_0_0_0_1;
int x_0_0_0_1_0;
int x_0_0_0_1_1;
int x_0_0_1_0_0;
int x_0_0_1_0_1;
int x_0_0_1_1_0;
int x_0_0_1_1_1;
int x_0_1_0_0_0;
int x_0_1_0_0_1;
int x_0_1_0_1_0;
int x_0_1_0_1_1;
int x_0_1_1_0_0;
int x_0_1_1_0_1;
int x_0_1_1_1_0;
int x_0_1_1_1_1;
int x_1_0_0_0_0;
int x_1_0_0_0_1;
int x_1_0_0_1_0;
int x_1_0_0_1_1;
int x_1_0_1_0_0;
int x_1_0_1_0_1;
int x_1_0_1_1_0;
int x_1_0_1_1_1;
int x_1_1_0_0_0;
int x_1_1_0_0_1;
int x_1_1_0_1_0;
int x_1_1_0_1_1;
int x_1_1_1_0_0;
int x_1_1_1_0_1;
int x_1_1_1_1_0;
int x_1_1_1_1_1;
Paul Fultz II
-- View this message in context: http://boost.2283326.n4.nabble.com/BOOST-PP-ERROR-0x0003-BOOST-PP-REPEAT-OVERFLOW-with-multiply-nested-BOOST-PP-REPEATS-tp4667949p4667961.html Sent from the Boost - Users mailing list archive at Nabble.com.
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