【发布时间】:2023-03-11 13:32:01
【问题描述】:
如果参数列表为空
#define key_evaluate(r, key, sig) key |= 1 << sig;
#define getKey(...)\
({\
ComponentKey key = 0;\
BOOST_PP_SEQ_FOR_EACH(key_evaluate, key, BOOST_PP_VARIADIC_TO_SEQ(__VA_ARGS__))
key;\
})
int main(void)
{
getKey();
}
扩展到
int main(void)
{
({
ComponentKey key = 0;
key |= 1 << ;
key;
})
}
但如果 _VA_ARGS_ 为空,我希望它扩展为空。 This 回答了这种类型的问题,但如果我使用它来代替
#define key_evaluate(r, key, sig) key |= 1 << sig;
#define convertToKey(...) BOOST_PP_SEQ_FOR_EACH(key_evaluate, key, BOOST_PP_VARIADIC_TO_SEQ(__VA_ARGS__))
#define components_convertToKey(...)\
({\
ComponentKey key = 0;\
BOOST_PP_IF(BOOST_PP_EQUAL(BOOST_PP_TUPLE_SIZE((,##__VA_ARGS__)), 1), \
BOOST_PP_EXPAND, convertToKey) (__VA_ARGS__) \
key;\
})
我收到此错误:error: ‘BOOST_PP_EXPAND’ undeclared。
这意味着 BOOST_PP_EXPAND 不会被预处理器替换,因为 BOOST_PP_EXPAND 在别处使用,这意味着它已定义。
【问题讨论】:
标签: c boost c-preprocessor