c++ move semantics for cv::Ptr<>
This commit is contained in:
parent
56cdd6f14f
commit
5a0af53683
@ -228,4 +228,23 @@
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
/****************************************************************************************\
|
||||
* C++ Move semantics *
|
||||
\****************************************************************************************/
|
||||
|
||||
#ifndef CV_CXX_MOVE_SEMANTICS
|
||||
# if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) || defined(_MSC_VER) && _MSC_VER >= 1600
|
||||
# define CV_CXX_MOVE_SEMANTICS 1
|
||||
# elif defined(__clang)
|
||||
# if __has_feature(cxx_rvalue_references)
|
||||
# define CV_CXX_MOVE_SEMANTICS 1
|
||||
# endif
|
||||
# endif
|
||||
#else
|
||||
# if CV_CXX_MOVE_SEMANTICS == 0
|
||||
# undef CV_CXX_MOVE_SEMANTICS
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#endif // __OPENCV_CORE_CVDEF_H__
|
||||
|
@ -411,6 +411,11 @@ struct Ptr
|
||||
template<typename Y>
|
||||
Ptr<Y> dynamicCast() const;
|
||||
|
||||
#ifdef CV_CXX_MOVE_SEMANTICS
|
||||
Ptr(Ptr&& o);
|
||||
Ptr& operator = (Ptr&& o);
|
||||
#endif
|
||||
|
||||
private:
|
||||
detail::PtrOwner* owner;
|
||||
T* stored;
|
||||
|
@ -252,6 +252,29 @@ Ptr<Y> Ptr<T>::dynamicCast() const
|
||||
return Ptr<Y>(*this, dynamic_cast<Y*>(stored));
|
||||
}
|
||||
|
||||
#ifdef CV_CXX_MOVE_SEMANTICS
|
||||
|
||||
template<typename T>
|
||||
Ptr<T>::Ptr(Ptr&& o) : owner(o.owner), stored(o.stored)
|
||||
{
|
||||
o.owner = NULL;
|
||||
o.stored = NULL;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
Ptr<T>& Ptr<T>::operator = (Ptr<T>&& o)
|
||||
{
|
||||
release();
|
||||
owner = o.owner;
|
||||
stored = o.stored;
|
||||
o.owner = NULL;
|
||||
o.stored = NULL;
|
||||
return *this;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
template<typename T>
|
||||
void swap(Ptr<T>& ptr1, Ptr<T>& ptr2){
|
||||
ptr1.swap(ptr2);
|
||||
|
Loading…
Reference in New Issue
Block a user