Visual Studio 2010 模拟“g++”是什么? -E 文件.cxx`?
有没有,我们可以在IDE中看到结果吗?
因此,我尝试使用 boost 预处理器的代码示例,此处显示(!警告 - 俄语):
#include <boost/preprocessor.hpp>
#include <iostream>
#include <string>
#include <map>
#include <vector>
#define DEFINE_OUR_STRUCT(name, seq) DEFINE_OUR_STRUCT_I(name, seq)
#define DEFINE_OUR_STRUCT_I(name, seq) \
struct name { \
DEFINE_OUR_STRUCT_ENUM_FIELDS(seq) \
\
template <typename functor> \
void apply(Functor functor) { \
DEFINE_OUR_STRUCT_ENUM_APPLY_FIELDS(functor, seq) \
} \
};
#define DEFINE_OUR_STRUCT_EXTRACT_TYPE(tuple) \
BOOST_PP_TUPLE_ELEM(2, 0, tuple)
#define DEFINE_OUR_STRUCT_EXTRACT_NAME(tuple) \
BOOST_PP_TUPLE_ELEM(2, 1, tuple)
#define DEFINE_OUR_STRUCT_ENUM_FIELDS(seq) \
BOOST_PP_SEQ_FOR_EACH( \
DEFINE_OUR_STRUCT_ENUM_FIELDS_OP, ~, seq)
#define DEFINE_OUR_STRUCT_ENUM_FIELDS_OP(z, data, el) \
DEFINE_OUR_STRUCT_EXTRACT_TYPE(el) \
DEFINE_OUR_STRUCT_EXTRACT_NAME(el);
#define DEFINE_OUR_STRUCT_ENUM_APPLY_FIELDS(ft, seq) \
BOOST_PP_SEQ_FOR_EACH( \
DEFINE_OUR_STRUCT_ENUM_APPLY_FIELDS_OP, ft, seq)
#define DEFINE_OUR_STRUCT_ENUM_APPLY_FIELDS_OP(z, ft, el) \
ft(DEFINE_OUR_STRUCT_EXTRACT_NAME(el));
//this
DEFINE_OUR_STRUCT(first_struct,
((int , id))
((std::vector<char> , data))
)
// shall turn into
/*
struct first_struct {
int id;
std::vector<char> data;
template <typename Functor>
void apply(Functor functor) {
functor(id);
functor(data);
}
};
*/
// ...And probably shall not give as many errors as it does...
int main()
{
return 0;
}
我的 IDE 是 VS2010(终极版),我想知道如何以 IDE 的方式查看我的代码 - 意味着我的定义变成了代码。可以在IDE内部完成,可以从VS consol完成吗?
Is there any, can we see results in IDE?
So I try code sample that uses boost preprocessor and is shown here (!warning - russian):
#include <boost/preprocessor.hpp>
#include <iostream>
#include <string>
#include <map>
#include <vector>
#define DEFINE_OUR_STRUCT(name, seq) DEFINE_OUR_STRUCT_I(name, seq)
#define DEFINE_OUR_STRUCT_I(name, seq) \
struct name { \
DEFINE_OUR_STRUCT_ENUM_FIELDS(seq) \
\
template <typename functor> \
void apply(Functor functor) { \
DEFINE_OUR_STRUCT_ENUM_APPLY_FIELDS(functor, seq) \
} \
};
#define DEFINE_OUR_STRUCT_EXTRACT_TYPE(tuple) \
BOOST_PP_TUPLE_ELEM(2, 0, tuple)
#define DEFINE_OUR_STRUCT_EXTRACT_NAME(tuple) \
BOOST_PP_TUPLE_ELEM(2, 1, tuple)
#define DEFINE_OUR_STRUCT_ENUM_FIELDS(seq) \
BOOST_PP_SEQ_FOR_EACH( \
DEFINE_OUR_STRUCT_ENUM_FIELDS_OP, ~, seq)
#define DEFINE_OUR_STRUCT_ENUM_FIELDS_OP(z, data, el) \
DEFINE_OUR_STRUCT_EXTRACT_TYPE(el) \
DEFINE_OUR_STRUCT_EXTRACT_NAME(el);
#define DEFINE_OUR_STRUCT_ENUM_APPLY_FIELDS(ft, seq) \
BOOST_PP_SEQ_FOR_EACH( \
DEFINE_OUR_STRUCT_ENUM_APPLY_FIELDS_OP, ft, seq)
#define DEFINE_OUR_STRUCT_ENUM_APPLY_FIELDS_OP(z, ft, el) \
ft(DEFINE_OUR_STRUCT_EXTRACT_NAME(el));
//this
DEFINE_OUR_STRUCT(first_struct,
((int , id))
((std::vector<char> , data))
)
// shall turn into
/*
struct first_struct {
int id;
std::vector<char> data;
template <typename Functor>
void apply(Functor functor) {
functor(id);
functor(data);
}
};
*/
// ...And probably shall not give as many errors as it does...
int main()
{
return 0;
}
My IDE is VS2010 (ultimate), I wonder how to see my code as IDE sees it - meanig with my define turned into code. Can it be done inside IDE, can it be done from VS consol?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
CL /E
从命令行运行 Visual Studio 编译器,以执行与 gcc 的-E
等效的操作(即预处理)。我不知道有什么方法可以从 IDE 本身做到这一点。正如 @MooingDuck 所说,您可以将预处理后的源输出到可配置文件,您可以从 IDE 中查看该文件,尽管您无法将预处理后的输出直接打印到 IDE 输出窗口 AFAIK。
You can run the Visual Studio compiler from the commandline with
CL /E
to do the equivalent of gcc's-E
(i.e. preprocessed). I'm not aware of a way to do this from the IDE itself.As @MooingDuck says, you can output preprocessed source to a configurable file which you can view from the IDE although you can't get the preprocessed output to spool directly to an IDE output window AFAIK.