DenseStorage safely copy/swap.

Fixes #2229.

For dynamic matrices with fixed-sized storage, only copy/swap
elements that have been set.  Otherwise, this leads to inefficient
copying, and potential UB for non-initialized elements.
This commit is contained in:
Antonio Sanchez
2021-04-21 15:45:31 -07:00
committed by Rasmus Munk Larsen
parent 85a76a16ea
commit d213a0bcea
5 changed files with 199 additions and 78 deletions

View File

@@ -566,6 +566,17 @@ template<typename T> struct smart_memmove_helper<T,false> {
}
};
#if EIGEN_HAS_RVALUE_REFERENCES
template<typename T> EIGEN_DEVICE_FUNC T* smart_move(T* start, T* end, T* target)
{
return std::move(start, end, target);
}
#else
template<typename T> EIGEN_DEVICE_FUNC T* smart_move(T* start, T* end, T* target)
{
return std::copy(start, end, target);
}
#endif
/*****************************************************************************
*** Implementation of runtime stack allocation (falling back to malloc) ***