简体   繁体   English

BOOST_PP_SEQ_ENUM空序列

[英]BOOST_PP_SEQ_ENUM on an empty sequence

How could I write a macro that is like BOOST_PP_SEQ_ENUM , but handles the empty sequence, ie 我怎么能写一个类似于BOOST_PP_SEQ_ENUM的宏,但是要处理空序列,即

#define SEQ (a)(b)
MY_BOOST_PP_SEQ_ENUM(SEQ) // expands to a,b
#define SEQ
MY_BOOST_PP_SEQ_ENUM(SEQ) // expands to nothing

There was a solution to this problem proposed here , named add #define BOOST_PP_SEQ_ENUM_0 . 这里提出一个解决方案,名为add #define BOOST_PP_SEQ_ENUM_0 It was rejected with the comment "no such thing as an empty sequence", but that seems to solve my problem. 它以“没有空序列之类的东西”的评论被拒绝,但这似乎解决了我的问题。

You just need to define SEQ as an empty sequence: 您只需要将SEQ定义为空序列:

#define SEQ ()

and you can use BOOST_PP_SEQ_ENUM directly. 您可以直接使用BOOST_PP_SEQ_ENUM

Works here with Boost 1.47 using G++ 4.7.1 and VC 2010. 在此处使用G ++ 4.7.1和VC 2010与Boost 1.47配合使用。

You can use this: 您可以使用此:

#define PP_SEQ_ENUM(x) BOOST_PP_CAT(PP_SEQ_ENUM_0 x, _END)
#define PP_SEQ_ENUM_0(x) x PP_SEQ_ENUM_1
#define PP_SEQ_ENUM_1(x) , x PP_SEQ_ENUM_2
#define PP_SEQ_ENUM_2(x) , x PP_SEQ_ENUM_1
#define PP_SEQ_ENUM_0_END
#define PP_SEQ_ENUM_1_END
#define PP_SEQ_ENUM_2_END 

This should work for sequences of any size(even ones greater than 256) 这应该适用于任何大小的序列(甚至大于256的序列)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM