From bd72e4a8c4f2bc41d3b4a87be7d5e850efaa461d Mon Sep 17 00:00:00 2001 From: Erik Schultheis Date: Wed, 5 Jan 2022 00:46:09 +0000 Subject: [PATCH] ensure that eigen::internal::size is not found by ADL, rename to ssize and... (cherry picked from commit 9210e71fb378a0f1542272506dc2759b6c147237) --- Eigen/src/Core/IndexedView.h | 4 ++-- Eigen/src/Core/util/Meta.h | 25 +++++++++++++++++++------ Eigen/src/plugins/IndexedViewMethods.h | 6 +++--- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/Eigen/src/Core/IndexedView.h b/Eigen/src/Core/IndexedView.h index 08476251d..9d41c391f 100644 --- a/Eigen/src/Core/IndexedView.h +++ b/Eigen/src/Core/IndexedView.h @@ -122,10 +122,10 @@ public: {} /** \returns number of rows */ - Index rows() const { return internal::size(m_rowIndices); } + Index rows() const { return internal::index_list_size(m_rowIndices); } /** \returns number of columns */ - Index cols() const { return internal::size(m_colIndices); } + Index cols() const { return internal::index_list_size(m_colIndices); } /** \returns the nested expression */ const typename internal::remove_all::type& diff --git a/Eigen/src/Core/util/Meta.h b/Eigen/src/Core/util/Meta.h index 81ae2a32d..0e21fe37f 100755 --- a/Eigen/src/Core/util/Meta.h +++ b/Eigen/src/Core/util/Meta.h @@ -466,20 +466,33 @@ template struct array_size > { }; #endif + /** \internal - * Analogue of the std::size free function. - * It returns the size of the container or view \a x of type \c T + * Analogue of the std::ssize free function. + * It returns the signed size of the container or view \a x of type \c T * * It currently supports: * - any types T defining a member T::size() const * - plain C arrays as T[N] * + * For C++20, this function just forwards to `std::ssize`, or any ADL discoverable `ssize` function. */ -template -EIGEN_CONSTEXPR Index size(const T& x) { return x.size(); } +#if EIGEN_COMP_CXXVER < 20 +template +EIGEN_CONSTEXPR auto index_list_size(const T& x) { + using R = std::common_type_t>; + return static_cast(x.size()); +} -template -EIGEN_CONSTEXPR Index size(const T (&) [N]) { return N; } +template +EIGEN_CONSTEXPR std::ptrdiff_t index_list_size(const T (&)[N]) { return N; } +#else +template +EIGEN_CONSTEXPR auto index_list_size(T&& x) { + using std::ssize; + return ssize(std::forward(x)); +} +#endif // EIGEN_COMP_CXXVER /** \internal * Convenient struct to get the result type of a nullary, unary, binary, or diff --git a/Eigen/src/plugins/IndexedViewMethods.h b/Eigen/src/plugins/IndexedViewMethods.h index 5bfb19ac6..15c35b0bf 100644 --- a/Eigen/src/plugins/IndexedViewMethods.h +++ b/Eigen/src/plugins/IndexedViewMethods.h @@ -90,8 +90,8 @@ operator()(const RowIndices& rowIndices, const ColIndices& colIndices) EIGEN_IND return BlockType(derived(), internal::first(actualRowIndices), internal::first(actualColIndices), - internal::size(actualRowIndices), - internal::size(actualColIndices)); + internal::index_list_size(actualRowIndices), + internal::index_list_size(actualColIndices)); } // The following overload returns a Scalar @@ -168,7 +168,7 @@ operator()(const Indices& indices) EIGEN_INDEXED_VIEW_METHOD_CONST EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) typename IvcType::type actualIndices = ivcSize(indices); return VectorBlock::value> - (derived(), internal::first(actualIndices), internal::size(actualIndices)); + (derived(), internal::first(actualIndices), internal::index_list_size(actualIndices)); } template