From 306aa0e69912aadf41d36f08c3e483e4d2f8805b Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Sat, 15 Aug 2015 17:42:39 +0300 Subject: [PATCH] c++ move semantics for cv::Mat_ --- modules/core/include/opencv2/core/mat.hpp | 10 ++++ modules/core/include/opencv2/core/mat.inl.hpp | 50 +++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/modules/core/include/opencv2/core/mat.hpp b/modules/core/include/opencv2/core/mat.hpp index 68c667ea82..05ce64c409 100644 --- a/modules/core/include/opencv2/core/mat.hpp +++ b/modules/core/include/opencv2/core/mat.hpp @@ -2089,6 +2089,16 @@ public: template operator Vec::channel_type, n>() const; //! conversion to Matx template operator Matx::channel_type, m, n>() const; + +#ifdef CV_CXX_MOVE_SEMANTICS + Mat_(Mat_&& m); + Mat_& operator = (Mat_&& m); + + Mat_(Mat&& m); + Mat_& operator = (Mat&& m); + + Mat_(MatExpr&& e); +#endif }; typedef Mat_ Mat1b; diff --git a/modules/core/include/opencv2/core/mat.inl.hpp b/modules/core/include/opencv2/core/mat.inl.hpp index 7f3e871495..61ae94de08 100644 --- a/modules/core/include/opencv2/core/mat.inl.hpp +++ b/modules/core/include/opencv2/core/mat.inl.hpp @@ -1718,6 +1718,56 @@ void Mat_<_Tp>::forEach(const Functor& operation) const { Mat::forEach<_Tp, Functor>(operation); } +#ifdef CV_CXX_MOVE_SEMANTICS + +template inline +Mat_<_Tp>::Mat_(Mat_&& m) + : Mat(m) +{ +} + +template inline +Mat_<_Tp>& Mat_<_Tp>::operator = (Mat_&& m) +{ + Mat::operator = (m); + return *this; +} + +template inline +Mat_<_Tp>::Mat_(Mat&& m) + : Mat() +{ + flags = (flags & ~CV_MAT_TYPE_MASK) | DataType<_Tp>::type; + *this = m; +} + +template inline +Mat_<_Tp>& Mat_<_Tp>::operator = (Mat&& m) +{ + if( DataType<_Tp>::type == m.type() ) + { + Mat::operator = (m); + return *this; + } + if( DataType<_Tp>::depth == m.depth() ) + { + return (*this = m.reshape(DataType<_Tp>::channels, m.dims, 0)); + } + CV_DbgAssert(DataType<_Tp>::channels == m.channels()); + m.convertTo(*this, type()); + return *this; +} + +template inline +Mat_<_Tp>::Mat_(MatExpr&& e) + : Mat() +{ + flags = (flags & ~CV_MAT_TYPE_MASK) | DataType<_Tp>::type; + *this = Mat(e); +} + +#endif + ///////////////////////////// SparseMat ///////////////////////////// inline