修改 BOOST_PP_SEQ

Modifying BOOST_PP_SEQ

我有一些序列:(a)(1)(b)(2)(c)(3),我想将它扩展到:a_b_c,有什么解决方案?我尝试了 BOOST_PP_SEQ_FOLD_LEFTBOOST_PP_SEQ_FILTER 但没有成功,它是:a1b2c3 ... 帮助)

你可以这样做(我不能保证这是最好的方法):

#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