Boost 预处理器:示例不起作用
#include <boost/preprocessor/seq/insert.hpp>
#define SEQ (a)(b)(d)
BOOST_PP_SEQ_INSERT(SEQ, 2, c) // expands to (a)(b)(c)(d)
在 Visual Studio 2008 上,我收到错误错误 C2065: 'b': 未声明的标识符
示例是否有问题,或者我是否缺少某些内容?
请注意:序列定义本身就可以。为了展示这一点,我编译了这段代码:
#include <boost/preprocessor/cat.hpp>
#include <boost/preprocessor/seq/for_each.hpp>
#define SEQ (w)(x)
#define MACRO(r, data, elem) BOOST_PP_CAT(elem, data)
struct w_
{
int x;
};
void test()
{
BOOST_PP_SEQ_FOR_EACH(MACRO, _, SEQ);
x_.x = 3;
}
免责声明:这段代码是 WTF 代码,我从来没有打算像这样使用 BOOST PP :-)
I tried to compile a sample from the Boost.Preprocessor library which is:
#include <boost/preprocessor/seq/insert.hpp>
#define SEQ (a)(b)(d)
BOOST_PP_SEQ_INSERT(SEQ, 2, c) // expands to (a)(b)(c)(d)
on Visual Studio 2008 and I get the error error C2065: 'b' : undeclared identifier
Is there a problem with the sample or am I missing something??
Please note: The sequence definition itself is ok. To show this, I compiled this code:
#include <boost/preprocessor/cat.hpp>
#include <boost/preprocessor/seq/for_each.hpp>
#define SEQ (w)(x)
#define MACRO(r, data, elem) BOOST_PP_CAT(elem, data)
struct w_
{
int x;
};
void test()
{
BOOST_PP_SEQ_FOR_EACH(MACRO, _, SEQ);
x_.x = 3;
}
DISCLAIMER: this code is WTF code, and I never intended to use BOOST PP like this :-)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,您正在尝试编译一个源文件,其中包含:
我想您应该将其放在该代码有意义的上下文中,或者只运行预处理器(不编译结果)。
Well, you are trying to compile a source file containing:
I suppose you should either put this in a context where this code makes sense, or just run the preprocessor (without compiling the result).