diff --git a/Eigen/src/Core/Matrix.h b/Eigen/src/Core/Matrix.h
index 53d10fd31..2fc38c812 100644
--- a/Eigen/src/Core/Matrix.h
+++ b/Eigen/src/Core/Matrix.h
@@ -139,6 +139,9 @@ class Matrix
&& SizeAtCompileTime!=Dynamic && ((sizeof(Scalar)*SizeAtCompileTime)%16)==0 };
EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF(NeedsToAlign)
+ Base& base() { return *static_cast(this); }
+ const Base& base() const { return *static_cast(this); }
+
EIGEN_STRONG_INLINE int rows() const { return m_storage.rows(); }
EIGEN_STRONG_INLINE int cols() const { return m_storage.cols(); }
@@ -487,13 +490,8 @@ class Matrix
/** Override MatrixBase::swap() since for dynamic-sized matrices of same type it is enough to swap the
* data pointers.
*/
- inline void swap(Matrix& other)
- {
- if (Base::SizeAtCompileTime==Dynamic)
- m_storage.swap(other.m_storage);
- else
- this->Base::swap(other);
- }
+ template
+ void swap(const MatrixBase& other);
/** \name Map
* These are convenience functions returning Map objects. The Map() static functions return unaligned Map objects,
@@ -652,8 +650,38 @@ class Matrix
m_storage.data()[0] = x;
m_storage.data()[1] = y;
}
+
+ template
+ friend struct ei_matrix_swap_impl;
};
+template::ret,
+ bool IsDynamicSize = MatrixType::SizeAtCompileTime==Dynamic>
+struct ei_matrix_swap_impl
+{
+ static inline void run(MatrixType& matrix, MatrixBase& other)
+ {
+ matrix.base().swap(other);
+ }
+};
+
+template
+struct ei_matrix_swap_impl
+{
+ static inline void run(MatrixType& matrix, MatrixBase& other)
+ {
+ matrix.m_storage.swap(other.derived().m_storage);
+ }
+};
+
+template
+template
+inline void Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>::swap(const MatrixBase& other)
+{
+ ei_matrix_swap_impl::run(*this, *const_cast*>(&other));
+}
+
/** \defgroup matrixtypedefs Global matrix typedefs
*
* \ingroup Core_Module