aboutsummaryrefslogtreecommitdiffhomepage
path: root/Eigen/src/Core/Matrix.h
diff options
context:
space:
mode:
authorGravatar Benoit Jacob <jacob.benoit.1@gmail.com>2009-09-03 01:25:40 -0400
committerGravatar Benoit Jacob <jacob.benoit.1@gmail.com>2009-09-03 01:25:40 -0400
commit7d18c30641a57cde5246614e3f7dd88fe867a7b0 (patch)
treed41c1037a33d17a23a309905ae1396927ffbf0db /Eigen/src/Core/Matrix.h
parent7586f7f706dbeeeed431d63e6d5990f8cb773caa (diff)
finally the first version was the good one...
Diffstat (limited to 'Eigen/src/Core/Matrix.h')
-rw-r--r--Eigen/src/Core/Matrix.h38
1 files changed, 31 insertions, 7 deletions
diff --git a/Eigen/src/Core/Matrix.h b/Eigen/src/Core/Matrix.h
index caa8d4be6..2fc38c812 100644
--- a/Eigen/src/Core/Matrix.h
+++ b/Eigen/src/Core/Matrix.h
@@ -490,13 +490,8 @@ class Matrix
/** Override MatrixBase::swap() since for dynamic-sized matrices of same type it is enough to swap the
* data pointers.
*/
- using Base::swap;
- inline void swap(Matrix& other)
- {
- ei_assert(rows() == other.rows() && cols() == other.cols());
- m_storage.swap(other.m_storage);
- // FIXME what about using this->Base::swap(other); for fixed size ?
- }
+ template<typename OtherDerived>
+ void swap(const MatrixBase<OtherDerived>& other);
/** \name Map
* These are convenience functions returning Map objects. The Map() static functions return unaligned Map objects,
@@ -655,8 +650,37 @@ class Matrix
m_storage.data()[0] = x;
m_storage.data()[1] = y;
}
+
+ template<typename MatrixType, typename OtherDerived, bool IsSameType, bool IsDynamicSize>
+ friend struct ei_matrix_swap_impl;
+};
+
+template<typename MatrixType, typename OtherDerived,
+ bool IsSameType = ei_is_same_type<MatrixType, OtherDerived>::ret,
+ bool IsDynamicSize = MatrixType::SizeAtCompileTime==Dynamic>
+struct ei_matrix_swap_impl
+{
+ static inline void run(MatrixType& matrix, MatrixBase<OtherDerived>& other)
+ {
+ matrix.base().swap(other);
+ }
};
+template<typename MatrixType, typename OtherDerived>
+struct ei_matrix_swap_impl<MatrixType, OtherDerived, true, true>
+{
+ static inline void run(MatrixType& matrix, MatrixBase<OtherDerived>& other)
+ {
+ matrix.m_storage.swap(other.derived().m_storage);
+ }
+};
+
+template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
+template<typename OtherDerived>
+inline void Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>::swap(const MatrixBase<OtherDerived>& other)
+{
+ ei_matrix_swap_impl<Matrix, OtherDerived>::run(*this, *const_cast<MatrixBase<OtherDerived>*>(&other));
+}
/** \defgroup matrixtypedefs Global matrix typedefs
*