From 7d18c30641a57cde5246614e3f7dd88fe867a7b0 Mon Sep 17 00:00:00 2001 From: Benoit Jacob Date: Thu, 3 Sep 2009 01:25:40 -0400 Subject: finally the first version was the good one... --- Eigen/src/Core/Matrix.h | 38 +++++++++++++++++++++++++++++++------- 1 file 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 + void swap(const MatrixBase& 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 + 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 * -- cgit v1.2.3