用途:html
BOOST_PP_SEQ_FOR_EACH宏,用於將一個序列中參數依次按照指定宏進行展開。
spa
語法:code
BOOST_PP_SEQ_FOR_EACH(macro, data, seq)
macro
htm
一個以格式macro(r, data, elem)定義的三元宏。該宏被BOOST_PP_SEQ_FOR_EACH按照seq中每一個元素進行展開。展開該宏,須要用到下一個BOOST_PP_FOR的重複項、備用數據data和當前元素。blog
data
ip
備用數據,用於傳給macroget
seq
it
用於供macro按照哪一個序列進行展開io
用法:class
BOOST_PP_SEQ_FOR_EACH是一個重複項的宏。
若是序列是(a)(b)(c),則展開爲:
macro(r, data, a) macro(r, data, b) macro(r, data, c)
若是要求更高效率,可以使用BOOST_PP_SEQ_FOR_EACH_R
頭文件:
<boost/preprocessor/seq/for_each.hpp>
示例代碼:
1.例1
#include <boost/preprocessor/cat.hpp> #include <boost/preprocessor/seq/for_each.hpp> #define SEQ (w)(x)(y)(z) #define MACRO(r, data, elem) BOOST_PP_CAT(elem, data) BOOST_PP_SEQ_FOR_EACH(MACRO, _, SEQ) // expands to w_ x_ y_ z_
2.例2
#include <boost/preprocessor/cat.hpp> #include <boost/preprocessor/seq/for_each.hpp> #define SEQ (w)(x)(y)(z) #define MACRO(r, data, elem) elem::GetInstance() BOOST_PP_SEQ_FOR_EACH(MACRO, _, SEQ) // expands to w::GetInstance() x::GetInstance() y::GetInstance() z::GetInstance()