使用BOOST_PP
I 可以将宏扩展为带有附加标记的多个逗号分隔值,如下面的代码所示。
但是,它在没有参数的情况下不起作用。
#define BOOST_PP_VARIADICS
#include <boost/preprocessor/punctuation/comma_if.hpp>
#include <boost/preprocessor/seq/for_each_i.hpp>
#include <boost/preprocessor/variadic/to_seq.hpp>
#define ADD_TOKEN(r, token, i, e) \
BOOST_PP_COMMA_IF(i) token(e)
#define WRAP(...) \
BOOST_PP_SEQ_FOR_EACH_I(ADD_TOKEN, decltype, BOOST_PP_VARIADIC_TO_SEQ(__VA_ARGS__))
#define MACRO(fmt, ...) \
Template<WRAP(__VA_ARGS__)>
MACRO("");
MACRO("", 0);
MACRO("", 0, 1);
编译时的输出gcc -E main.cpp
是
Template< decltype() >;
Template< decltype(0) >;
Template< decltype(0) , decltype(1) >;
如何MACRO
在没有__VA_ARGS__
参数的情况下将调用扩展到 null?
也就是说,我希望输出为:
Template< >;
Template< decltype(0) >;
Template< decltype(0) , decltype(1) >;
我怎样才能做到这一点?