我找不到一种使用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似乎是不可转换的。
我基本上希望迭代具有相同接口但包含不同值的模板对象(容器)列表。实现这一目标的更好方法是值得欢迎的。
发布于 2016-10-04 14:25:59
tuple_t是hana::type的一个元组。您想要一个普通对象的tuple,它就是tuple。
boost::hana::tuple<A, B> names;
boost::hana::for_each(names, [&](const auto& x) {
std::cout << x.name << std::endl;
});https://stackoverflow.com/questions/39854510
复制相似问题