【发布时间】:2016-10-04 14:08:59
【问题描述】:
我找不到通过hana::for_each 遍历元组来访问真实对象的方法。
struct A {
std::string name;
}
struct B {
std::string name;
}
using type_t = decltype(boost::hana::tuple_t<A, B>);
type_t names;
boost::hana::for_each(names, [&](const auto& a) {
std::cout << a.name << std::endl;
});
a 的类型似乎是 hana::tuple_impl<...>,并且似乎不能转换为其基础类型 decltype(std::decay_t<a>)::type。
我基本上想遍历具有相同接口但包含不同值的模板化对象(容器)列表。欢迎使用更好的方法来实现这一目标。
【问题讨论】:
-
我怀疑这个
decltype(boost::hana::tuple_t<A, B>)。这是什么意思?tuple_t<A,B>本身不是 type 吗? -
@Nawaz 文档说它的用法是这样的
auto types = hana::tuple_t<int*, char&, void>;所以我猜它是一个 C++14 变量模板。 boost.org/doc/libs/1_61_0/libs/hana/doc/html/index.html
标签: c++ boost boost-hana