【发布时间】:2020-07-22 17:17:55
【问题描述】:
我想定义一个INITIALIZE(...) 来实现以下目标
struct MyStruct {
std::string a;
bool b;
char c;
double d;
INITIALIZE(a, (b, true), (c, '$'), d);
};
扩展为
struct MyStruct {
std::string a;
bool b;
char c;
double d;
void init() {
a = get_value<std::string>(); // use return value of get_value function
b = true; // use init value from the macro
c = '$'; // use init value from the macro
d = get_value<double>(); // use return value of get_value function
}
};
这些可以在Boost_PP 宏的帮助下实现吗?
T get_value<T>() 在库中定义。
【问题讨论】:
-
感谢您的反馈。 @n.'代词'm。我已经用一个具体的例子更新了这个问题。
标签: c++ macros boost-preprocessor