遍历boost :: hana :: tuple [英] Iterating over boost::hana::tuple

查看:72
本文介绍了遍历boost :: hana :: tuple的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找不到通过元组迭代的 hana :: for_each 访问真实对象的方法.

I could not find a way to access real object with hana::for_each iterating over tuples.

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 .

Type of a appears to be hana::tuple_impl<...> and seems to be not-castable to its underlying type decltype(std::decay_t<a>)::type.

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

I basically want to iterate over a list of templated objects (containers) that have the same interface but contain different values. Better ways to achieve this is welcome.

推荐答案

tuple_t 用于 hana :: type s的元组.您需要一个普通对象的 tuple ,即 tuple :

tuple_t is for a tuple of hana::types. You want a tuple of normal objects, which is just tuple:

boost::hana::tuple<A, B> names;
boost::hana::for_each(names, [&](const auto& x) {
    std::cout << x.name << std::endl;
});

这篇关于遍历boost :: hana :: tuple的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆