【发布时间】:2018-05-30 19:08:30
【问题描述】:
是否存在用于在编译时将 Struct 概念的成员类型转换为类型名的 std::string 的 STL 容器的 Boost Hana 方法?
例如,
MyType t();
std::array<std::string, 3> ls = boost::hana::typesToString(t);
for(std::string x : ls){
std::cout << x << std::endl;
}
将“int string bool”生成为 STDOUT,
与
class MyType{
int x;
std::string y;
bool z;
}
文档清楚地提供了获取 Struct 概念实例的成员及其值的方法,但我还没有找到任何对成员类型执行此操作的方法。一个更简单的任务是:
int x;
std::string tName = boost::hana::typeId(x); //tName has value "int"
我已阅读 this post,但我想知道 Hana 中是否有一种开箱即用的干净方法。更好的方法是遍历 Struct 的成员,而不必知道它们的名称。
【问题讨论】:
标签: c++ boost boost-hana