mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-08-14 20:56:00 +08:00
much simpler fix for Matrix::swap
This commit is contained in:
parent
ec20d58317
commit
4a8258369a
@ -490,8 +490,13 @@ class Matrix
|
|||||||
/** Override MatrixBase::swap() since for dynamic-sized matrices of same type it is enough to swap the
|
/** Override MatrixBase::swap() since for dynamic-sized matrices of same type it is enough to swap the
|
||||||
* data pointers.
|
* data pointers.
|
||||||
*/
|
*/
|
||||||
template<typename OtherDerived>
|
using Base::swap;
|
||||||
void swap(const MatrixBase<OtherDerived>& other);
|
inline void swap(Matrix& other)
|
||||||
|
{
|
||||||
|
ei_assert(matrix.rows() == other.rows() && matrix.cols() == other.cols());
|
||||||
|
m_storage.swap(other.m_storage);
|
||||||
|
// FIXME what about using this->Base::swap(other); for fixed size ?
|
||||||
|
}
|
||||||
|
|
||||||
/** \name Map
|
/** \name Map
|
||||||
* These are convenience functions returning Map objects. The Map() static functions return unaligned Map objects,
|
* These are convenience functions returning Map objects. The Map() static functions return unaligned Map objects,
|
||||||
@ -650,38 +655,8 @@ class Matrix
|
|||||||
m_storage.data()[0] = x;
|
m_storage.data()[0] = x;
|
||||||
m_storage.data()[1] = y;
|
m_storage.data()[1] = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename MatrixType, typename OtherDerived, bool IsSameType>
|
|
||||||
friend struct ei_matrix_swap_impl;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename MatrixType, typename OtherDerived,
|
|
||||||
bool IsSameType = ei_is_same_type<MatrixType, OtherDerived>::ret>
|
|
||||||
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>
|
|
||||||
{
|
|
||||||
static inline void run(MatrixType& matrix, MatrixBase<OtherDerived>& other)
|
|
||||||
{
|
|
||||||
ei_assert(matrix.rows() == other.rows() && matrix.cols() == other.cols());
|
|
||||||
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
|
/** \defgroup matrixtypedefs Global matrix typedefs
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user