From e567135ed3abef3d228160a1e224433f0ee7cbbc Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Thu, 22 Mar 2018 14:57:10 +0300 Subject: [PATCH] next: force C++11 features unconditionally: CV_CXX_MOVE_SEMANTICS/CV_CXX_STD_ARRAY --- modules/core/include/opencv2/core/cvdef.h | 58 +++------------------------ modules/core/include/opencv2/core/cvstd.hpp | 2 - modules/core/include/opencv2/core/mat.hpp | 8 ---- modules/core/include/opencv2/core/mat.inl.hpp | 29 -------------- modules/core/include/opencv2/core/ptr.inl.hpp | 4 -- modules/core/test/test_mat.cpp | 2 - 6 files changed, 5 insertions(+), 98 deletions(-) diff --git a/modules/core/include/opencv2/core/cvdef.h b/modules/core/include/opencv2/core/cvdef.h index b424d14..7059a4d 100644 --- a/modules/core/include/opencv2/core/cvdef.h +++ b/modules/core/include/opencv2/core/cvdef.h @@ -421,63 +421,15 @@ Cv64suf; # error "OpenCV 4.x+ requires enabled C++11 support" #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 - -/****************************************************************************************\ -* C++11 std::array * -\****************************************************************************************/ - -#ifndef CV_CXX_STD_ARRAY -# if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1900/*MSVS 2015*/) -# define CV_CXX_STD_ARRAY 1 -# include -# endif -#else -# if CV_CXX_STD_ARRAY == 0 -# undef CV_CXX_STD_ARRAY -# endif -#endif - - -/****************************************************************************************\ -* C++11 override / final * -\****************************************************************************************/ - +#define CV_CXX_MOVE_SEMANTICS 1 +#define CV_CXX_STD_ARRAY 1 +#include #ifndef CV_OVERRIDE -# ifdef CV_CXX11 -# define CV_OVERRIDE override -# endif +# define CV_OVERRIDE override #endif -#ifndef CV_OVERRIDE -# define CV_OVERRIDE -#endif - #ifndef CV_FINAL -# ifdef CV_CXX11 -# define CV_FINAL final -# endif +# define CV_FINAL final #endif -#ifndef CV_FINAL -# define CV_FINAL -#endif - // Integer types portatibility diff --git a/modules/core/include/opencv2/core/cvstd.hpp b/modules/core/include/opencv2/core/cvstd.hpp index 453904e..ec2258b 100644 --- a/modules/core/include/opencv2/core/cvstd.hpp +++ b/modules/core/include/opencv2/core/cvstd.hpp @@ -386,10 +386,8 @@ struct Ptr template Ptr dynamicCast() const; -#ifdef CV_CXX_MOVE_SEMANTICS Ptr(Ptr&& o); Ptr& operator = (Ptr&& o); -#endif private: detail::PtrOwner* owner; diff --git a/modules/core/include/opencv2/core/mat.hpp b/modules/core/include/opencv2/core/mat.hpp index 627c7d1..9160037 100644 --- a/modules/core/include/opencv2/core/mat.hpp +++ b/modules/core/include/opencv2/core/mat.hpp @@ -196,10 +196,8 @@ public: _InputArray(const UMat& um); _InputArray(const std::vector& umv); -#ifdef CV_CXX_STD_ARRAY template _InputArray(const std::array<_Tp, _Nm>& arr); template _InputArray(const std::array& arr); -#endif Mat getMat(int idx=-1) const; Mat getMat_(int idx=-1) const; @@ -2052,10 +2050,8 @@ public: /** @overload */ template void forEach(const Functor& operation) const; -#ifdef CV_CXX_MOVE_SEMANTICS Mat(Mat&& m); Mat& operator = (Mat&& m); -#endif enum { MAGIC_VAL = 0x42FF0000, AUTO_STEP = 0, CONTINUOUS_FLAG = CV_MAT_CONT_FLAG, SUBMATRIX_FLAG = CV_SUBMAT_FLAG }; enum { MAGIC_MASK = 0xFFFF0000, TYPE_MASK = 0x00000FFF, DEPTH_MASK = 7 }; @@ -2319,7 +2315,6 @@ public: //! conversion to Matx template operator Matx::channel_type, m, n>() const; -#ifdef CV_CXX_MOVE_SEMANTICS Mat_(Mat_&& m); Mat_& operator = (Mat_&& m); @@ -2327,7 +2322,6 @@ public: Mat_& operator = (Mat&& m); Mat_(MatExpr&& e); -#endif }; typedef Mat_ Mat1b; @@ -2524,10 +2518,8 @@ public: //! returns N if the matrix is 1-channel (N x ptdim) or ptdim-channel (1 x N) or (N x 1); negative number otherwise int checkVector(int elemChannels, int depth=-1, bool requireContinuous=true) const; -#ifdef CV_CXX_MOVE_SEMANTICS UMat(UMat&& m); UMat& operator = (UMat&& m); -#endif /*! Returns the OpenCL buffer handle on which UMat operates on. The UMat instance should be kept alive during the use of the handle to prevent the buffer to be diff --git a/modules/core/include/opencv2/core/mat.inl.hpp b/modules/core/include/opencv2/core/mat.inl.hpp index dc1eadf..a8191b5 100644 --- a/modules/core/include/opencv2/core/mat.inl.hpp +++ b/modules/core/include/opencv2/core/mat.inl.hpp @@ -84,7 +84,6 @@ template inline _InputArray::_InputArray(const std::vector<_Tp>& vec) { init(FIXED_TYPE + STD_VECTOR + traits::Type<_Tp>::value + ACCESS_READ, &vec); } -#ifdef CV_CXX_STD_ARRAY template inline _InputArray::_InputArray(const std::array<_Tp, _Nm>& arr) { init(FIXED_TYPE + FIXED_SIZE + STD_ARRAY + traits::Type<_Tp>::value + ACCESS_READ, arr.data(), Size(1, _Nm)); } @@ -92,7 +91,6 @@ _InputArray::_InputArray(const std::array<_Tp, _Nm>& arr) template inline _InputArray::_InputArray(const std::array& arr) { init(STD_ARRAY_MAT + ACCESS_READ, arr.data(), Size(1, _Nm)); } -#endif inline _InputArray::_InputArray(const std::vector& vec) @@ -172,7 +170,6 @@ template inline _OutputArray::_OutputArray(std::vector<_Tp>& vec) { init(FIXED_TYPE + STD_VECTOR + traits::Type<_Tp>::value + ACCESS_WRITE, &vec); } -#ifdef CV_CXX_STD_ARRAY template inline _OutputArray::_OutputArray(std::array<_Tp, _Nm>& arr) { init(FIXED_TYPE + FIXED_SIZE + STD_ARRAY + traits::Type<_Tp>::value + ACCESS_WRITE, arr.data(), Size(1, _Nm)); } @@ -180,7 +177,6 @@ _OutputArray::_OutputArray(std::array<_Tp, _Nm>& arr) template inline _OutputArray::_OutputArray(std::array& arr) { init(STD_ARRAY_MAT + ACCESS_WRITE, arr.data(), Size(1, _Nm)); } -#endif inline _OutputArray::_OutputArray(std::vector&) @@ -214,7 +210,6 @@ template inline _OutputArray::_OutputArray(const std::vector<_Tp>& vec) { init(FIXED_TYPE + FIXED_SIZE + STD_VECTOR + traits::Type<_Tp>::value + ACCESS_WRITE, &vec); } -#ifdef CV_CXX_STD_ARRAY template inline _OutputArray::_OutputArray(const std::array<_Tp, _Nm>& arr) { init(FIXED_TYPE + FIXED_SIZE + STD_ARRAY + traits::Type<_Tp>::value + ACCESS_WRITE, arr.data(), Size(1, _Nm)); } @@ -222,7 +217,6 @@ _OutputArray::_OutputArray(const std::array<_Tp, _Nm>& arr) template inline _OutputArray::_OutputArray(const std::array& arr) { init(FIXED_SIZE + STD_ARRAY_MAT + ACCESS_WRITE, arr.data(), Size(1, _Nm)); } -#endif template inline _OutputArray::_OutputArray(const std::vector >& vec) @@ -291,7 +285,6 @@ template inline _InputOutputArray::_InputOutputArray(std::vector<_Tp>& vec) { init(FIXED_TYPE + STD_VECTOR + traits::Type<_Tp>::value + ACCESS_RW, &vec); } -#ifdef CV_CXX_STD_ARRAY template inline _InputOutputArray::_InputOutputArray(std::array<_Tp, _Nm>& arr) { init(FIXED_TYPE + FIXED_SIZE + STD_ARRAY + traits::Type<_Tp>::value + ACCESS_RW, arr.data(), Size(1, _Nm)); } @@ -299,7 +292,6 @@ _InputOutputArray::_InputOutputArray(std::array<_Tp, _Nm>& arr) template inline _InputOutputArray::_InputOutputArray(std::array& arr) { init(STD_ARRAY_MAT + ACCESS_RW, arr.data(), Size(1, _Nm)); } -#endif inline _InputOutputArray::_InputOutputArray(std::vector&) { CV_Error(Error::StsUnsupportedFormat, "std::vector cannot be an input/output array\n"); } @@ -328,7 +320,6 @@ template inline _InputOutputArray::_InputOutputArray(const std::vector<_Tp>& vec) { init(FIXED_TYPE + FIXED_SIZE + STD_VECTOR + traits::Type<_Tp>::value + ACCESS_RW, &vec); } -#ifdef CV_CXX_STD_ARRAY template inline _InputOutputArray::_InputOutputArray(const std::array<_Tp, _Nm>& arr) { init(FIXED_TYPE + FIXED_SIZE + STD_ARRAY + traits::Type<_Tp>::value + ACCESS_RW, arr.data(), Size(1, _Nm)); } @@ -336,7 +327,6 @@ _InputOutputArray::_InputOutputArray(const std::array<_Tp, _Nm>& arr) template inline _InputOutputArray::_InputOutputArray(const std::array& arr) { init(FIXED_SIZE + STD_ARRAY_MAT + ACCESS_RW, arr.data(), Size(1, _Nm)); } -#endif template inline _InputOutputArray::_InputOutputArray(const std::vector >& vec) @@ -594,7 +584,6 @@ Mat::Mat(const std::initializer_list sizes, const std::initializer_list<_Tp Mat((int)sizes.size(), (int*)sizes.begin(), traits::Type<_Tp>::value, (uchar*)list.begin()).copyTo(*this); } -#ifdef CV_CXX_STD_ARRAY template inline Mat::Mat(const std::array<_Tp, _Nm>& arr, bool copyData) : flags(MAGIC_VAL | traits::Type<_Tp>::value | CV_MAT_CONT_FLAG), dims(2), rows((int)arr.size()), @@ -611,7 +600,6 @@ Mat::Mat(const std::array<_Tp, _Nm>& arr, bool copyData) else Mat((int)arr.size(), 1, traits::Type<_Tp>::value, (uchar*)arr.data()).copyTo(*this); } -#endif template inline Mat::Mat(const Vec<_Tp, n>& vec, bool copyData) @@ -1261,7 +1249,6 @@ Mat::operator std::vector<_Tp>() const return v; } -#ifdef CV_CXX_STD_ARRAY template inline Mat::operator std::array<_Tp, _Nm>() const { @@ -1269,7 +1256,6 @@ Mat::operator std::array<_Tp, _Nm>() const copyTo(v); return v; } -#endif template inline Mat::operator Vec<_Tp, n>() const @@ -1337,8 +1323,6 @@ void Mat::push_back(const std::vector<_Tp>& v) push_back(Mat(v)); } -#ifdef CV_CXX_MOVE_SEMANTICS - inline Mat::Mat(Mat&& m) : flags(m.flags), dims(m.dims), rows(m.rows), cols(m.cols), data(m.data), @@ -1400,8 +1384,6 @@ Mat& Mat::operator = (Mat&& m) return *this; } -#endif - ///////////////////////////// MatSize //////////////////////////// @@ -1642,12 +1624,10 @@ Mat_<_Tp>::Mat_(const std::initializer_list sizes, std::initializer_list<_T : Mat(sizes, list) {} -#ifdef CV_CXX_STD_ARRAY template template inline Mat_<_Tp>::Mat_(const std::array<_Tp, _Nm>& arr, bool copyData) : Mat(arr, copyData) {} -#endif template inline Mat_<_Tp>& Mat_<_Tp>::operator = (const Mat& m) @@ -1935,7 +1915,6 @@ Mat_<_Tp>::operator std::vector<_Tp>() const return v; } -#ifdef CV_CXX_STD_ARRAY template template inline Mat_<_Tp>::operator std::array<_Tp, _Nm>() const { @@ -1943,7 +1922,6 @@ Mat_<_Tp>::operator std::array<_Tp, _Nm>() const copyTo(a); return a; } -#endif template template inline Mat_<_Tp>::operator Vec::channel_type, n>() const @@ -2007,8 +1985,6 @@ 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) @@ -2056,7 +2032,6 @@ Mat_<_Tp>::Mat_(MatExpr&& e) *this = Mat(e); } -#endif ///////////////////////////// SparseMat ///////////////////////////// @@ -3827,8 +3802,6 @@ size_t UMat::total() const return p; } -#ifdef CV_CXX_MOVE_SEMANTICS - inline UMat::UMat(UMat&& m) : flags(m.flags), dims(m.dims), rows(m.rows), cols(m.cols), allocator(m.allocator), @@ -3889,8 +3862,6 @@ UMat& UMat::operator = (UMat&& m) return *this; } -#endif - inline bool UMatData::hostCopyObsolete() const { return (flags & HOST_COPY_OBSOLETE) != 0; } inline bool UMatData::deviceCopyObsolete() const { return (flags & DEVICE_COPY_OBSOLETE) != 0; } diff --git a/modules/core/include/opencv2/core/ptr.inl.hpp b/modules/core/include/opencv2/core/ptr.inl.hpp index 466f634..9165de0 100644 --- a/modules/core/include/opencv2/core/ptr.inl.hpp +++ b/modules/core/include/opencv2/core/ptr.inl.hpp @@ -252,8 +252,6 @@ Ptr Ptr::dynamicCast() const return Ptr(*this, dynamic_cast(stored)); } -#ifdef CV_CXX_MOVE_SEMANTICS - template Ptr::Ptr(Ptr&& o) : owner(o.owner), stored(o.stored) { @@ -275,8 +273,6 @@ Ptr& Ptr::operator = (Ptr&& o) return *this; } -#endif - template void swap(Ptr& ptr1, Ptr& ptr2){ diff --git a/modules/core/test/test_mat.cpp b/modules/core/test/test_mat.cpp index bb149db..17bcd55 100644 --- a/modules/core/test/test_mat.cpp +++ b/modules/core/test/test_mat.cpp @@ -1608,7 +1608,6 @@ TEST(Mat, regression_7873_mat_vector_initialize) ASSERT_EQ(2, sub_mat.size[2]); } -#ifdef CV_CXX_STD_ARRAY TEST(Core_Mat_array, outputArray_create_getMat) { cv::Mat_ src_base(5, 1); @@ -1697,7 +1696,6 @@ TEST(Core_Mat_array, SplitMerge) EXPECT_EQ(0, cvtest::norm(src[i], dst[i], NORM_INF)); } } -#endif TEST(Mat, regression_8680) { -- 2.7.4