Skip to content

Commit 2b2cd85

Browse files
committed
bug #1573: add noexcept move constructor and move assignment operator to Quaternion
1 parent 43206ac commit 2b2cd85

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
@@ -105,6 +105,22 @@ class QuaternionBase : public RotationBase<Derived, 3>
105105
EIGEN_DEVICE_FUNC Derived& operator=(const AngleAxisType& aa);
106106
template<class OtherDerived> EIGEN_DEVICE_FUNC Derived& operator=(const MatrixBase<OtherDerived>& m);
107107

108+
#if EIGEN_HAS_RVALUE_REFERENCES
109+
// Because we have a user-defined copy assignment operator, we don't get an implicit move constructor or assignment operator.
110+
/** Default move constructor */
111+
EIGEN_DEVICE_FUNC inline QuaternionBase(QuaternionBase&& other) EIGEN_NOEXCEPT_IF(std::is_nothrow_move_constructible<Scalar>::value) = default;
112+
113+
/** Default move assignment operator */
114+
EIGEN_DEVICE_FUNC QuaternionBase& operator=(QuaternionBase&& other) EIGEN_NOEXCEPT_IF(std::is_nothrow_move_assignable<Scalar>::value) = default;
115+
116+
// And now because we declared a constructor, we don't get a default constructor or copy constructor. Say we want them.
117+
/** Default constructor */
118+
EIGEN_DEVICE_FUNC QuaternionBase() = default;
119+
120+
/** Copy constructor */
121+
EIGEN_DEVICE_FUNC QuaternionBase(const QuaternionBase& other) = default;
122+
#endif
123+
108124
/** \returns a quaternion representing an identity rotation
109125
* \sa MatrixBase::Identity()
110126
*/
@@ -276,6 +292,19 @@ class Quaternion : public QuaternionBase<Quaternion<_Scalar,_Options> >
276292
EIGEN_DEVICE_FUNC explicit inline Quaternion(const Quaternion<OtherScalar, OtherOptions>& other)
277293
{ m_coeffs = other.coeffs().template cast<Scalar>(); }
278294

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

281310
template<typename Derived1, typename Derived2>

0 commit comments

Comments
 (0)