mgambhir
mgambhir

Reputation: 60

Multiple arguments for data in BOOST_PP_REPEAT

I want to use BOOST_PP_REPEAT(count, macro, data) and my macro looks like

`TEMPLATE (z, n, x, y)

BOOST_PP_REPEAT (5, TEMPLATE, 4, 5)`

It complains about BOOST_PP_REPEAT being passed 4 arguments while it only expects 3. Is there a way to pack two arguments into the "data" parameter of BOOST_PP_REPEAT.

Thanks!

Upvotes: 1

Views: 1828

Answers (2)

Igor R.
Igor R.

Reputation: 15075

Use BOOST_PP_TUPLE_ELEM:

#define TEMPLATE (z, n, data) use_first(BOOST_PP_TUPLE_ELEM(2, 0, data)); use_second(BOOST_PP_TUPLE_ELEM(2, 1, data));
#define YOUR_MACRO(n, arg1, arg2) BOOST_PP_REPEAT(5, TEMPLATE, (arg1, arg2))

Upvotes: 2

Potatoswatter
Potatoswatter

Reputation: 137850

Make the argument list a distinct argument with nested parentheses:

BOOST_PP_REPEAT (5, TEMPLATE_2ARG, (4, 5))

Then strip the extra parens from inside TEMPLATE_2ARG.

#define STRIP_PARENS( ... ) __VA_ARGS__

#define TEMPLATE_2ARG( I, ARGS ) TEMPLATE( I, STRIP_PARENS ARGS )
#define TEMPLATE( I, X, Y ) whatever

Upvotes: 1

Related Questions