迭代boost :: hana :: tuple

Eth*_*one 2 c++ boost boost-hana

我无法通过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;
    });
Run Code Online (Sandbox Code Playgroud)

类型a似乎是hana::tuple_impl<...>并且似乎不可转换为其基础类型decltype(std::decay_t<a>)::type.

我基本上想要迭代一个具有相同接口但包含不同值的模板化对象(容器)列表.实现这一目标的更好方法是受欢迎的

Bar*_*rry 9

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;
});
Run Code Online (Sandbox Code Playgroud)