【发布时间】:2012-07-30 20:34:35
【问题描述】:
我想创建一个定义来解析函数签名并使用 Boost Preprocessor 创建如下内容:
MY_DEFINE std::string fun(int t, float b)
{
或至少:
MY_DEFINE(std::string)(fun)(int t, float b)
{
这会产生:
class fun_in
{
int t;
float b;
}
class fun_out
{
std::string value;
}
void my_fun_wrapper(int t, float b)
{
}
std::string fun(int t, float b)
{
my_fun_wrapper(t, b);
对于每个具有该定义的函数。
是否可以通过 Boost 预处理器为 N 传入参数和任何返回类型的函数创建这样的定义包装器?
【问题讨论】:
-
return是 C++ 中的保留字 - 不要将其用作结构成员名称。 -
您希望
MY_DEFINE扩展为依赖于它之后的内容? -
MY_DEFINE type name(type x, type y)是必需的语法吗?为什么不MY_DEFINE(type, name, type1, x, type2, y)或者最后一部分可变参数。 -
不幸的是,我非常相信您提出的语法是不可能的。毕竟,您需要宏才能使用参数。现在它没有,宏无法查询解析器接下来会看到什么。
-
@myWallJSON 您是否意识到您无法编辑预处理器生成的任何代码?
标签: c++ boost boost-preprocessor