【问题标题】:boost hana index_if and type提升 hana index_if 和类型
【发布时间】:2018-09-18 14:48:40
【问题描述】:

我想知道为什么在这段代码中,i 的类型是一个空的可选项。

auto t = boost::hana::make_tuple(boost::hana::type_c<int>, boost::hana::type_c<double>);
auto i = boost::hana::index_if(t, boost::hana::is_a<boost::hana::type<double>>);

对我来说应该是optional&lt;hana::size_t&lt;1&gt;&gt;

我知道有Boost hana get index of first matching,但不是完全相同的问题

【问题讨论】:

    标签: c++ boost boost-hana


    【解决方案1】:

    boost::hana::is_a 返回对象的 tag 是否匹配给定的标签。 [reference]

    您没有传递标签,而是传递hana::type

    例如,您可以测试参数是否为hana::type,而i 将包含size_c&lt;0&gt;(因为元组中的第一项已经是hana::type):

    auto i = hana::index_if(t, hana::is_a<hana::type_tag>);
    

    如果您想检查某种类型是否相等,请使用equal::to

    auto i = hana::index_if(t, hana::equal.to(hana::type_c<double>));
    

    [Reference to hana::equal]

    Live example

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-16
      • 1970-01-01
      相关资源
      最近更新 更多