From bb73be8a2e8da00c1cf5d26acb9fe47a87b8047f Mon Sep 17 00:00:00 2001 From: Charles Schlosser Date: Mon, 4 Nov 2024 17:55:27 +0000 Subject: [PATCH] make fixed-size objects trivially move assignable --- Eigen/src/Core/Array.h | 5 +---- Eigen/src/Core/ArrayBase.h | 6 ++++-- Eigen/src/Core/DenseBase.h | 7 ++++--- Eigen/src/Core/Matrix.h | 6 +----- Eigen/src/Core/MatrixBase.h | 2 ++ Eigen/src/Core/PlainObjectBase.h | 5 +---- test/dense_storage.cpp | 2 ++ 7 files changed, 15 insertions(+), 18 deletions(-) diff --git a/Eigen/src/Core/Array.h b/Eigen/src/Core/Array.h index 2098749c0..7819305ce 100644 --- a/Eigen/src/Core/Array.h +++ b/Eigen/src/Core/Array.h @@ -123,10 +123,7 @@ class Array : public PlainObjectBase::value) { - Base::operator=(std::move(other)); - return *this; - } + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr Array& operator=(Array&&) = default; /** \copydoc PlainObjectBase(const Scalar& a0, const Scalar& a1, const Scalar& a2, const Scalar& a3, const * ArgTypes&... args) diff --git a/Eigen/src/Core/ArrayBase.h b/Eigen/src/Core/ArrayBase.h index 6237df454..de2dafd5c 100644 --- a/Eigen/src/Core/ArrayBase.h +++ b/Eigen/src/Core/ArrayBase.h @@ -147,8 +147,10 @@ class ArrayBase : public DenseBase { // inline void evalTo(Dest& dst) const { dst = matrix(); } protected: - EIGEN_DEFAULT_COPY_CONSTRUCTOR(ArrayBase) - EIGEN_DEFAULT_EMPTY_CONSTRUCTOR_AND_DESTRUCTOR(ArrayBase) + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr ArrayBase() = default; + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr ArrayBase(const ArrayBase&) = default; + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr ArrayBase(ArrayBase&&) = default; + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr ArrayBase& operator=(ArrayBase&&) = default; private: explicit ArrayBase(Index); diff --git a/Eigen/src/Core/DenseBase.h b/Eigen/src/Core/DenseBase.h index e1fbb0b82..1a84bd56c 100644 --- a/Eigen/src/Core/DenseBase.h +++ b/Eigen/src/Core/DenseBase.h @@ -573,12 +573,12 @@ class DenseBase #else typedef std::conditional_t<(Flags & DirectAccessBit) == DirectAccessBit, internal::pointer_based_stl_iterator, - internal::generic_randaccess_stl_iterator > + internal::generic_randaccess_stl_iterator> iterator_type; typedef std::conditional_t<(Flags & DirectAccessBit) == DirectAccessBit, internal::pointer_based_stl_iterator, - internal::generic_randaccess_stl_iterator > + internal::generic_randaccess_stl_iterator> const_iterator_type; // Stl-style iterators are supported only for vectors. @@ -619,8 +619,9 @@ class DenseBase } protected: - EIGEN_DEFAULT_COPY_CONSTRUCTOR(DenseBase) /** Default constructor. Do nothing. */ + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseBase(const DenseBase&) = default; + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr DenseBase& operator=(DenseBase&&) = default; #ifdef EIGEN_INTERNAL_DEBUGGING EIGEN_DEVICE_FUNC constexpr DenseBase() { /* Just checks for self-consistency of the flags. diff --git a/Eigen/src/Core/Matrix.h b/Eigen/src/Core/Matrix.h index 8b7f70c16..522e9c4ff 100644 --- a/Eigen/src/Core/Matrix.h +++ b/Eigen/src/Core/Matrix.h @@ -256,11 +256,7 @@ class Matrix : public PlainObjectBase::value) { - Base::operator=(std::move(other)); - return *this; - } + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr Matrix& operator=(Matrix&&) = default; /** \copydoc PlainObjectBase(const Scalar&, const Scalar&, const Scalar&, const Scalar&, const ArgTypes&... args) * diff --git a/Eigen/src/Core/MatrixBase.h b/Eigen/src/Core/MatrixBase.h index 81d5a97ea..481b6c128 100644 --- a/Eigen/src/Core/MatrixBase.h +++ b/Eigen/src/Core/MatrixBase.h @@ -138,6 +138,8 @@ class MatrixBase : public DenseBase { */ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& operator=(const MatrixBase& other); + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr MatrixBase& operator=(MatrixBase&&) = default; + // We cannot inherit here via Base::operator= since it is causing // trouble with MSVC. diff --git a/Eigen/src/Core/PlainObjectBase.h b/Eigen/src/Core/PlainObjectBase.h index 8720c4473..81b9b44ca 100644 --- a/Eigen/src/Core/PlainObjectBase.h +++ b/Eigen/src/Core/PlainObjectBase.h @@ -474,10 +474,7 @@ class PlainObjectBase : public internal::dense_xpr_base::type protected: EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr PlainObjectBase() = default; EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr PlainObjectBase(PlainObjectBase&&) = default; - EIGEN_DEVICE_FUNC constexpr PlainObjectBase& operator=(PlainObjectBase&& other) EIGEN_NOEXCEPT { - m_storage = std::move(other.m_storage); - return *this; - } + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr PlainObjectBase& operator=(PlainObjectBase&&) = default; /** Copy constructor */ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr PlainObjectBase(const PlainObjectBase&) = default; diff --git a/test/dense_storage.cpp b/test/dense_storage.cpp index 5d0083fa7..da30440e7 100644 --- a/test/dense_storage.cpp +++ b/test/dense_storage.cpp @@ -27,7 +27,9 @@ static_assert(std::is_trivially_copyable::value, "DenseStorage #endif static_assert(std::is_trivially_move_constructible::value, "Matrix4f not trivially_move_constructible"); +static_assert(std::is_trivially_move_assignable::value, "Matrix4f not trivially_move_assignable"); static_assert(std::is_trivially_move_constructible::value, "Array4f not trivially_move_constructible"); +static_assert(std::is_trivially_move_assignable::value, "Array4f not trivially_move_assignable"); #if !defined(EIGEN_DENSE_STORAGE_CTOR_PLUGIN) static_assert(std::is_trivially_copy_constructible::value, "Matrix4f not trivially_copy_constructible"); static_assert(std::is_trivially_copy_constructible::value, "Array4f not trivially_copy_constructible");