【发布时间】:2022-01-23 22:42:43
【问题描述】:
Here std::ranges::size 应该返回一个无符号整数。但是,当我在 Eigen 向量(使用 Eigen 3.4)上使用它时,以下编译:
Eigen::VectorXd x;
static_assert(std::same_as<Eigen::VectorXd::Index,
decltype(std::ranges::size(x))>);
其中Eigen::VectorXd::Index 是众所周知的有符号整数。通过查看std::ranges::size 的实现,我注意到返回类型是从x.size() 的返回类型推断出来的,也就是Eigen::VectorXd::Index。这是std::ranges::size 的错误吗?或者这是预期的?
2021 年 12 月 27 日更新
上面链接的C++参考页最终改变了std::ranges::size函数的描述:它只返回一个整数,不一定是无符号的!
【问题讨论】:
-
容器的
size()方法应该返回一个无符号整数。问题出在 Eigen 这边。 -
Otherwise, t.size() converted to its decayed type, if ranges::disable_sized_range<std::remove_cv_t<T>> is false, and the converted expression is valid and has an integer-like type.对于返回大小的签名类型的容器,似乎未指定。
标签: c++ eigen c++20 eigen3 std-ranges