From c367ed26a8949c4f4478d6616d0c3feaa3066498 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20S=C3=A1nchez?= Date: Wed, 16 Feb 2022 17:47:51 +0000 Subject: [PATCH] Make FixedInt constexpr, fix ODR of fix --- Eigen/src/Core/util/IntegralConstant.h | 30 +++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/Eigen/src/Core/util/IntegralConstant.h b/Eigen/src/Core/util/IntegralConstant.h index 4d198d270..da9cccbf5 100644 --- a/Eigen/src/Core/util/IntegralConstant.h +++ b/Eigen/src/Core/util/IntegralConstant.h @@ -53,7 +53,14 @@ template class FixedInt public: static const int value = N; EIGEN_CONSTEXPR operator int() const { return value; } - FixedInt() {} + + EIGEN_CONSTEXPR + FixedInt() = default; + + EIGEN_CONSTEXPR + FixedInt(std::integral_constant) {} + + EIGEN_CONSTEXPR FixedInt( VariableAndFixedInt other) { #ifndef EIGEN_INTERNAL_DEBUGGING EIGEN_UNUSED_VARIABLE(other); @@ -61,28 +68,41 @@ public: eigen_internal_assert(int(other)==N); } + EIGEN_CONSTEXPR FixedInt<-N> operator-() const { return FixedInt<-N>(); } + template + EIGEN_CONSTEXPR FixedInt operator+( FixedInt) const { return FixedInt(); } + template + EIGEN_CONSTEXPR FixedInt operator-( FixedInt) const { return FixedInt(); } + template + EIGEN_CONSTEXPR FixedInt operator*( FixedInt) const { return FixedInt(); } + template + EIGEN_CONSTEXPR FixedInt operator/( FixedInt) const { return FixedInt(); } + template + EIGEN_CONSTEXPR FixedInt operator%( FixedInt) const { return FixedInt(); } + template + EIGEN_CONSTEXPR FixedInt operator|( FixedInt) const { return FixedInt(); } + template + EIGEN_CONSTEXPR FixedInt operator&( FixedInt) const { return FixedInt(); } // Needed in C++14 to allow fix(): - FixedInt operator() () const { return *this; } + EIGEN_CONSTEXPR FixedInt operator() () const { return *this; } VariableAndFixedInt operator() (int val) const { return VariableAndFixedInt(val); } - - FixedInt(std::integral_constant) {} }; /** \internal @@ -163,7 +183,7 @@ template struct cleanup_index_type -static const internal::FixedInt fix{}; +constexpr internal::FixedInt fix{}; #else // EIGEN_PARSED_BY_DOXYGEN