【发布时间】:2015-09-15 00:02:01
【问题描述】:
这个问题是基于
我想效仿
namespace foo::bar::baz {
在 C++17 到来之前使用宏。
我的想法是:
#define BOOST_PP_VARIADICS
#include <boost/preprocessor/cat.hpp>
#include <boost/preprocessor/seq/fold_left.hpp>
#include <boost/preprocessor/variadic/to_seq.hpp>
#define OP(s, state, x) BOOST_PP_CAT(state, BOOST_PP_CAT( { namespace, x )) {
#define NS(...) namespace BOOST_PP_SEQ_FOLD_LEFT(OP, BOOST_PP_SEQ_HEAD(BOOST_PP_VARIADIC_TO_SEQ(__VA_ARGS__)), BOOST_PP_SEQ_TAIL(BOOST_PP_VARIADIC_TO_SEQ(__VA_ARGS__)))
NS(foo, bar, baz)
基于第二个链接,但这给了我:
namespace foo { namespacebar { namespacebaz {
如何在namespace 和标识符之间添加空格?
编辑:
如果你可以制作一个宏,让ns(foo::bar::baz) 扩展为namespace foo { namespace bar { namespace baz {,那就更好了。
【问题讨论】:
标签: c++ macros c-preprocessor