Skip to content

Commit 54b23a6

Browse files
committed
bug #1573: add noexcept move constructor and move assignment operator to Quaternion
Ported from upstream eigen
1 parent ec75eca commit 54b23a6

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

Eigen/src/Geometry/Quaternion.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,22 @@ class QuaternionBase : public RotationBase<Derived, 3>
100100
EIGEN_DEVICE_FUNC Derived& operator=(const AngleAxisType& aa);
101101
template<class OtherDerived> EIGEN_DEVICE_FUNC Derived& operator=(const MatrixBase<OtherDerived>& m);
102102

103+
#if EIGEN_HAS_RVALUE_REFERENCES
104+
// Because we have a user-defined copy assignment operator, we don't get an implicit move constructor or assignment operator.
105+
/** Default move constructor */
106+
EIGEN_DEVICE_FUNC inline QuaternionBase(QuaternionBase&& other) EIGEN_NOEXCEPT_IF(std::is_nothrow_move_constructible<Scalar>::value) = default;
107+
108+
/** Default move assignment operator */
109+
EIGEN_DEVICE_FUNC QuaternionBase& operator=(QuaternionBase&& other) EIGEN_NOEXCEPT_IF(std::is_nothrow_move_assignable<Scalar>::value) = default;
110+
111+
// And now because we declared a constructor, we don't get a default constructor or copy constructor. Say we want them.
112+
/** Default constructor */
113+
EIGEN_DEVICE_FUNC QuaternionBase() = default;
114+
115+
/** Copy constructor */
116+
EIGEN_DEVICE_FUNC QuaternionBase(const QuaternionBase& other) = default;
117+
#endif
118+
103119
/** \returns a quaternion representing an identity rotation
104120
* \sa MatrixBase::Identity()
105121
*/
@@ -271,6 +287,19 @@ class Quaternion : public QuaternionBase<Quaternion<_Scalar,_Options> >
271287
EIGEN_DEVICE_FUNC explicit inline Quaternion(const Quaternion<OtherScalar, OtherOptions>& other)
272288
{ m_coeffs = other.coeffs().template cast<Scalar>(); }
273289

290+
#if EIGEN_HAS_RVALUE_REFERENCES
291+
// We define a copy constructor, which means we don't get an implicit move constructor or assignment operator.
292+
/** Default move constructor */
293+
EIGEN_DEVICE_FUNC inline Quaternion(Quaternion&& other) EIGEN_NOEXCEPT_IF(std::is_nothrow_move_constructible<Scalar>::value) = default;
294+
295+
/** Default move assignment operator */
296+
EIGEN_DEVICE_FUNC Quaternion& operator=(Quaternion&& other) EIGEN_NOEXCEPT_IF(std::is_nothrow_move_assignable<Scalar>::value) = default;
297+
298+
// And now because we declared a constructor, we don't get an implicit copy constructor. Say we want one.
299+
/** Default copy constructor */
300+
EIGEN_DEVICE_FUNC Quaternion(const Quaternion& other) = default;
301+
#endif
302+
274303
EIGEN_DEVICE_FUNC static Quaternion UnitRandom();
275304

276305
template<typename Derived1, typename Derived2>

0 commit comments

Comments
 (0)