Here it is written that std::ranges::size
should return an unsigned integer. However, when I use it on an Eigen vector (with Eigen 3.4) the following compiles:
Eigen::VectorXd x;
static_assert(std::same_as<Eigen::VectorXd::Index,
decltype(std::ranges::size(x))>);
where Eigen::VectorXd::Index
is notoriously a signed integer. By looking at the implementation of std::ranges::size
, I noticed that the return type is inferred from the return type of x.size()
, which is precisely Eigen::VectorXd::Index
. Is this a bug of std::ranges::size
? Or is this expected?
Update 27/12/2021
The C++ reference page linked above has eventually changed the description of the std::ranges::size
function: it only returns an integer, not necessarily an unsigned one!