这个问题基于以下两篇文章:
我希望能够模拟:
在C++17发布之前,可以使用宏来实现这个功能。
我的想法是:
基于第二个链接,但这给了我:
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 {
,那就更好了。