c++ - boost hana index_if and type
问题描述
I wonder why, in this code, the type of i
is an empty optional.
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>>
I know there is Boost hana get index of first matching but it is not exactly the same question
解决方案
boost::hana::is_a
返回对象的标签是否与给定的标签匹配。[参考]
您没有将标签传递给它,hana::type
而是将其传递给它。
例如,您可以测试参数是否为 a hana::type
,并且i
是否包含 a size_c<0>
(因为元组中的第一项已经是 a 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>));
推荐阅读
- javascript - JQuery datepicker:禁用日期显式启用
- javascript - 在 Vue.js 中加载图像时显示微调器
- python - 从 Eclipse (PyDev) 迁移到 VS Code 时出现相对路径错误
- allure - “mvn allure:serve”向临时文件夹生成报告
- python - 无法使用 Python 请求模块登录
- sas - 在SAS中的小数位前加零
- javascript - 实例模式和使用 cloudflare、p5js 的问题
- botframework - 从 Teams 中任何类型的聊天(个人、群聊或频道)中获取成员?
- php - 根据年份选择更改 wp 查询
- ios - 两指向下滑动返回菜单