Boost Preprocessor is so cool

#include "boost/preprocessor/seq/size.hpp"
#include "boost/preprocessor/seq/elem.hpp"
#include "boost/preprocessor/seq/push_back.hpp"
#include "boost/preprocessor/stringize.hpp"
#include "boost/preprocessor/iteration/local.hpp"

#include "boost/preprocessor/arithmetic/add.hpp"
#include "boost/preprocessor/arithmetic/div.hpp"
#include "boost/preprocessor/arithmetic/mul.hpp"
#include "boost/preprocessor/arithmetic/dec.hpp"
#include "boost/preprocessor/arithmetic/mod.hpp"

#include "boost/preprocessor/debug/assert.hpp"
#include "boost/preprocessor/comparison/equal.hpp"

#define SEQ_DIM 4
#define SEQ0 (a)(b)(c)(d) \
             (a1)(b1)(c1)(d1)

BOOST_PP_ASSERT_MSG(BOOST_PP_EQUAL(BOOST_PP_MOD(BOOST_PP_SEQ_SIZE(SEQ0), SEQ_DIM), 0), \
					"#error SEQ has to be aligned with 4")

#define BOOST_PP_LOCAL_MACRO(n) printf("%s %s %s %s\n",			 \
		BOOST_PP_STRINGIZE(BOOST_PP_SEQ_ELEM(BOOST_PP_ADD(BOOST_PP_MUL(n, SEQ_DIM), 0), SEQ0)), \
		BOOST_PP_STRINGIZE(BOOST_PP_SEQ_ELEM(BOOST_PP_ADD(BOOST_PP_MUL(n, SEQ_DIM), 1), SEQ0)), \
		BOOST_PP_STRINGIZE(BOOST_PP_SEQ_ELEM(BOOST_PP_ADD(BOOST_PP_MUL(n, SEQ_DIM), 2), SEQ0)), \
		BOOST_PP_STRINGIZE(BOOST_PP_SEQ_ELEM(BOOST_PP_ADD(BOOST_PP_MUL(n, SEQ_DIM), 3), SEQ0))	);

#define BOOST_PP_LOCAL_LIMITS (0, BOOST_PP_DEC(BOOST_PP_DIV(BOOST_PP_SEQ_SIZE(SEQ0), SEQ_DIM)))
#include BOOST_PP_LOCAL_ITERATE()

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章