next: force C++11 features unconditionally: CV_CXX_MOVE_SEMANTICS/CV_CXX_STD_ARRAY

pull/11256/head
Alexander Alekhin 7 years ago
parent 98c8584b88
commit e567135ed3
  1. 58
      modules/core/include/opencv2/core/cvdef.h
  2. 2
      modules/core/include/opencv2/core/cvstd.hpp
  3. 8
      modules/core/include/opencv2/core/mat.hpp
  4. 29
      modules/core/include/opencv2/core/mat.inl.hpp
  5. 4
      modules/core/include/opencv2/core/ptr.inl.hpp
  6. 2
      modules/core/test/test_mat.cpp

@ -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 <array>
# 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 <array>
#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

@ -386,10 +386,8 @@ 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;

@ -196,10 +196,8 @@ public:
_InputArray(const UMat& um);
_InputArray(const std::vector<UMat>& umv);
#ifdef CV_CXX_STD_ARRAY
template<typename _Tp, std::size_t _Nm> _InputArray(const std::array<_Tp, _Nm>& arr);
template<std::size_t _Nm> _InputArray(const std::array<Mat, _Nm>& arr);
#endif
Mat getMat(int idx=-1) const;
Mat getMat_(int idx=-1) const;
@ -2052,10 +2050,8 @@ public:
/** @overload */
template<typename _Tp, typename Functor> 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<int m, int n> operator Matx<typename DataType<_Tp>::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_<uchar> 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

@ -84,7 +84,6 @@ template<typename _Tp> 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<typename _Tp, std::size_t _Nm> 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<std::size_t _Nm> inline
_InputArray::_InputArray(const std::array<Mat, _Nm>& arr)
{ init(STD_ARRAY_MAT + ACCESS_READ, arr.data(), Size(1, _Nm)); }
#endif
inline
_InputArray::_InputArray(const std::vector<bool>& vec)
@ -172,7 +170,6 @@ template<typename _Tp> 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<typename _Tp, std::size_t _Nm> 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<std::size_t _Nm> inline
_OutputArray::_OutputArray(std::array<Mat, _Nm>& arr)
{ init(STD_ARRAY_MAT + ACCESS_WRITE, arr.data(), Size(1, _Nm)); }
#endif
inline
_OutputArray::_OutputArray(std::vector<bool>&)
@ -214,7 +210,6 @@ template<typename _Tp> 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<typename _Tp, std::size_t _Nm> 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<std::size_t _Nm> inline
_OutputArray::_OutputArray(const std::array<Mat, _Nm>& arr)
{ init(FIXED_SIZE + STD_ARRAY_MAT + ACCESS_WRITE, arr.data(), Size(1, _Nm)); }
#endif
template<typename _Tp> inline
_OutputArray::_OutputArray(const std::vector<std::vector<_Tp> >& vec)
@ -291,7 +285,6 @@ template<typename _Tp> 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<typename _Tp, std::size_t _Nm> 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<std::size_t _Nm> inline
_InputOutputArray::_InputOutputArray(std::array<Mat, _Nm>& arr)
{ init(STD_ARRAY_MAT + ACCESS_RW, arr.data(), Size(1, _Nm)); }
#endif
inline _InputOutputArray::_InputOutputArray(std::vector<bool>&)
{ CV_Error(Error::StsUnsupportedFormat, "std::vector<bool> cannot be an input/output array\n"); }
@ -328,7 +320,6 @@ template<typename _Tp> 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<typename _Tp, std::size_t _Nm> 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<std::size_t _Nm> inline
_InputOutputArray::_InputOutputArray(const std::array<Mat, _Nm>& arr)
{ init(FIXED_SIZE + STD_ARRAY_MAT + ACCESS_RW, arr.data(), Size(1, _Nm)); }
#endif
template<typename _Tp> inline
_InputOutputArray::_InputOutputArray(const std::vector<std::vector<_Tp> >& vec)
@ -594,7 +584,6 @@ Mat::Mat(const std::initializer_list<int> 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<typename _Tp, std::size_t _Nm> 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<typename _Tp, int n> 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<typename _Tp, std::size_t _Nm> 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<typename _Tp, int n> 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<int> sizes, std::initializer_list<_T
: Mat(sizes, list)
{}
#ifdef CV_CXX_STD_ARRAY
template<typename _Tp> template<std::size_t _Nm> inline
Mat_<_Tp>::Mat_(const std::array<_Tp, _Nm>& arr, bool copyData)
: Mat(arr, copyData)
{}
#endif
template<typename _Tp> 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<typename _Tp> template<std::size_t _Nm> 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<typename _Tp> template<int n> inline
Mat_<_Tp>::operator Vec<typename DataType<_Tp>::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<typename _Tp> 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; }

@ -252,8 +252,6 @@ 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)
{
@ -275,8 +273,6 @@ Ptr<T>& Ptr<T>::operator = (Ptr<T>&& o)
return *this;
}
#endif
template<typename T>
void swap(Ptr<T>& ptr1, Ptr<T>& ptr2){

@ -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_<uchar> 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)
{

Loading…
Cancel
Save