[英]boost hana index_if and type
I wonder why, in this code, the type of i
is an empty optional. 我不知道为什么在这段代码中,
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>>);
To me, it should be optional<hana::size_t<1>>
对我来说,它应该是
optional<hana::size_t<1>>
I know there is Boost hana get index of first matching but it is not exactly the same question 我知道有Boost Hana获取第一个匹配项的索引,但这不是完全相同的问题
boost::hana::is_a
returns whether the tag of an object matches a given tag. boost::hana::is_a
返回对象的标签是否与给定的标签匹配。 [reference] [参考]
You're not passing it a tag, you're passing it a hana::type
instead. 您没有为其传递标签,而是为其传递了
hana::type
。
For example, you could test whether the argument is a hana::type
, and i
would contain a size_c<0>
(because the first item in the tuple is already a hana::type
): 例如,您可以测试参数是否为
hana::type
,并且i
将包含size_c<0>
(因为元组中的第一项已经是hana::type
):
auto i = hana::index_if(t, hana::is_a<hana::type_tag>);
If you want to check for equality to some type, use equal::to
: 如果要检查某种类型的
equal::to
,请使用equal::to
:
auto i = hana::index_if(t, hana::equal.to(hana::type_c<double>));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.