Skip to content

ensure that eigen::internal::size is not found by ADL, rename to ssize and...

This is an attempt at solving #2391 (closed) The naive idea would be to use std::size when available (C++17), and otherwise define Eigen::internal::size. However, these is a subtle difference between the std:: version and the Eigen version, in that std version is generally expected to return an unsigned value. C++20 defines ssize which is specifically for signed size values.

Technically, the size function in Eigen is compatible with the std version for Eigen types, as that is defined to return whatever the underlying object.size() returns. But for std types and arrays the return types would differ.

Therefore, I have changed the function name to ssize and put an implementation compatible with the standard (I hope, it is based on https://en.cppreference.com/w/cpp/iterator/size). Since this is an internal function, the name change should be OK I think.

There is still a slight subtlety, in that the std ssize function returns std::common_type_t<std::ptrdiff_t, std::make_signed_t<decltype(c.size())>>, which means that if the user redefined Eigen::Index to be smaller than std::ptrdiff_t, the old version would return a value of type Eigen::Index but the new one std::ptrdiff_t.

Merge request reports

Loading