Modifying BOOST_PP_SEQ

112 views Asked by At

I have some sequence: (a)(1)(b)(2)(c)(3) and I want to expand it in: a_b_c, what solutions? I tried BOOST_PP_SEQ_FOLD_LEFT vs BOOST_PP_SEQ_FILTER but unsuccessfully, it's was: a1b2c3 ... Help)

1

There are 1 answers

0
llonesmiz On BEST ANSWER

You could do something like this (I can't guarantee it's the best approach):

#define DO_CONCAT_WITH_UNDERSCORE(__,STATE,ELEM) BOOST_PP_CAT(STATE,BOOST_PP_CAT(_,ELEM))
#define DO_FILTER_POSITION(_,__,INDEX,ELEM) BOOST_PP_IF(BOOST_PP_MOD(INDEX,2),BOOST_PP_EMPTY(),(ELEM)) //IF IT'S ODD ADD NOTHING, IF IT'S EVEN ADD THE CURRENT ELEM IN PARENS
#define TAKE_EVEN_POSITIONS(SEQ) BOOST_PP_SEQ_FOR_EACH_I(DO_FILTER_POSITION,_,SEQ)
#define TAKE_EVEN_POSITIONS_AND_CONCAT_HELPER(FILTERED_SEQ) BOOST_PP_SEQ_FOLD_LEFT(DO_CONCAT_WITH_UNDERSCORE,BOOST_PP_SEQ_HEAD(FILTERED_SEQ),BOOST_PP_SEQ_TAIL(FILTERED_SEQ))
#define TAKE_EVEN_POSITIONS_AND_CONCAT(SEQ) TAKE_EVEN_POSITIONS_AND_CONCAT_HELPER(TAKE_EVEN_POSITIONS(SEQ))

Running on Wandbox