Merge pull request #11899 from arnaudbrejeon:moveable_types
authorArnaud Brejeon <arnaud.brejeon+github@gmail.com>
Fri, 6 Jul 2018 20:36:08 +0000 (13:36 -0700)
committerAlexander Alekhin <alexander.a.alekhin@gmail.com>
Fri, 6 Jul 2018 20:36:08 +0000 (23:36 +0300)
Add missing constructors and operator= (#11899)

modules/core/include/opencv2/core/types.hpp

index 16f7b30..7c3b56f 100644 (file)
@@ -163,10 +163,12 @@ public:
     Point_();
     Point_(_Tp _x, _Tp _y);
     Point_(const Point_& pt);
+    Point_(Point_&& pt) noexcept;
     Point_(const Size_<_Tp>& sz);
     Point_(const Vec<_Tp, 2>& v);
 
     Point_& operator = (const Point_& pt);
+    Point_& operator = (Point_&& pt) noexcept;
     //! conversion to another data type
     template<typename _Tp2> operator Point_<_Tp2>() const;
 
@@ -243,10 +245,12 @@ public:
     Point3_();
     Point3_(_Tp _x, _Tp _y, _Tp _z);
     Point3_(const Point3_& pt);
+    Point3_(Point3_&& pt) noexcept;
     explicit Point3_(const Point_<_Tp>& pt);
     Point3_(const Vec<_Tp, 3>& v);
 
     Point3_& operator = (const Point3_& pt);
+    Point3_& operator = (Point3_&& pt) noexcept;
     //! conversion to another data type
     template<typename _Tp2> operator Point3_<_Tp2>() const;
     //! conversion to cv::Vec<>
@@ -317,9 +321,11 @@ public:
     Size_();
     Size_(_Tp _width, _Tp _height);
     Size_(const Size_& sz);
+    Size_(Size_&& sz) noexcept;
     Size_(const Point_<_Tp>& pt);
 
     Size_& operator = (const Size_& sz);
+    Size_& operator = (Size_&& sz) noexcept;
     //! the area (width*height)
     _Tp area() const;
     //! aspect ratio (width/height)
@@ -420,10 +426,12 @@ public:
     Rect_();
     Rect_(_Tp _x, _Tp _y, _Tp _width, _Tp _height);
     Rect_(const Rect_& r);
+    Rect_(Rect_&& r) noexcept;
     Rect_(const Point_<_Tp>& org, const Size_<_Tp>& sz);
     Rect_(const Point_<_Tp>& pt1, const Point_<_Tp>& pt2);
 
     Rect_& operator = ( const Rect_& r );
+    Rect_& operator = ( Rect_&& r ) noexcept;
     //! the top-left corner
     Point_<_Tp> tl() const;
     //! the bottom-right corner
@@ -633,6 +641,12 @@ public:
     Scalar_(_Tp v0, _Tp v1, _Tp v2=0, _Tp v3=0);
     Scalar_(_Tp v0);
 
+    Scalar_(const Scalar_& s);
+    Scalar_(Scalar_&& s) noexcept;
+
+    Scalar_& operator=(const Scalar_& s);
+    Scalar_& operator=(Scalar_&& s) noexcept;
+
     template<typename _Tp2, int cn>
     Scalar_(const Vec<_Tp2, cn>& v);
 
@@ -1148,6 +1162,10 @@ Point_<_Tp>::Point_(const Point_& pt)
     : x(pt.x), y(pt.y) {}
 
 template<typename _Tp> inline
+Point_<_Tp>::Point_(Point_&& pt) noexcept
+    : x(std::move(pt.x)), y(std::move(pt.y)) {}
+
+template<typename _Tp> inline
 Point_<_Tp>::Point_(const Size_<_Tp>& sz)
     : x(sz.width), y(sz.height) {}
 
@@ -1162,6 +1180,13 @@ Point_<_Tp>& Point_<_Tp>::operator = (const Point_& pt)
     return *this;
 }
 
+template<typename _Tp> inline
+Point_<_Tp>& Point_<_Tp>::operator = (Point_&& pt) noexcept
+{
+    x = std::move(pt.x); y = std::move(pt.y);
+    return *this;
+}
+
 template<typename _Tp> template<typename _Tp2> inline
 Point_<_Tp>::operator Point_<_Tp2>() const
 {
@@ -1404,6 +1429,10 @@ Point3_<_Tp>::Point3_(const Point3_& pt)
     : x(pt.x), y(pt.y), z(pt.z) {}
 
 template<typename _Tp> inline
+Point3_<_Tp>::Point3_(Point3_&& pt) noexcept
+    : x(std::move(pt.x)), y(std::move(pt.y)), z(std::move(pt.z)) {}
+
+template<typename _Tp> inline
 Point3_<_Tp>::Point3_(const Point_<_Tp>& pt)
     : x(pt.x), y(pt.y), z(_Tp()) {}
 
@@ -1431,6 +1460,13 @@ Point3_<_Tp>& Point3_<_Tp>::operator = (const Point3_& pt)
 }
 
 template<typename _Tp> inline
+Point3_<_Tp>& Point3_<_Tp>::operator = (Point3_&& pt) noexcept
+{
+    x = std::move(pt.x); y = std::move(pt.y); z = std::move(pt.z);
+    return *this;
+}
+
+template<typename _Tp> inline
 _Tp Point3_<_Tp>::dot(const Point3_& pt) const
 {
     return saturate_cast<_Tp>(x*pt.x + y*pt.y + z*pt.z);
@@ -1647,6 +1683,10 @@ Size_<_Tp>::Size_(const Size_& sz)
     : width(sz.width), height(sz.height) {}
 
 template<typename _Tp> inline
+Size_<_Tp>::Size_(Size_&& sz) noexcept
+    : width(std::move(sz.width)), height(std::move(sz.height)) {}
+
+template<typename _Tp> inline
 Size_<_Tp>::Size_(const Point_<_Tp>& pt)
     : width(pt.x), height(pt.y) {}
 
@@ -1664,6 +1704,13 @@ Size_<_Tp>& Size_<_Tp>::operator = (const Size_<_Tp>& sz)
 }
 
 template<typename _Tp> inline
+Size_<_Tp>& Size_<_Tp>::operator = (Size_<_Tp>&& sz) noexcept
+{
+    width = std::move(sz.width); height = std::move(sz.height);
+    return *this;
+}
+
+template<typename _Tp> inline
 _Tp Size_<_Tp>::area() const
 {
     const _Tp result = width * height;
@@ -1778,6 +1825,10 @@ Rect_<_Tp>::Rect_(const Rect_<_Tp>& r)
     : x(r.x), y(r.y), width(r.width), height(r.height) {}
 
 template<typename _Tp> inline
+Rect_<_Tp>::Rect_(Rect_<_Tp>&& r) noexcept
+    : x(std::move(r.x)), y(std::move(r.y)), width(std::move(r.width)), height(std::move(r.height)) {}
+
+template<typename _Tp> inline
 Rect_<_Tp>::Rect_(const Point_<_Tp>& org, const Size_<_Tp>& sz)
     : x(org.x), y(org.y), width(sz.width), height(sz.height) {}
 
@@ -1801,6 +1852,16 @@ Rect_<_Tp>& Rect_<_Tp>::operator = ( const Rect_<_Tp>& r )
 }
 
 template<typename _Tp> inline
+Rect_<_Tp>& Rect_<_Tp>::operator = ( Rect_<_Tp>&& r ) noexcept
+{
+    x = std::move(r.x);
+    y = std::move(r.y);
+    width = std::move(r.width);
+    height = std::move(r.height);
+    return *this;
+}
+
+template<typename _Tp> inline
 Point_<_Tp> Rect_<_Tp>::tl() const
 {
     return Point_<_Tp>(x,y);
@@ -1984,8 +2045,6 @@ inline
 RotatedRect::RotatedRect(const Point2f& _center, const Size2f& _size, float _angle)
     : center(_center), size(_size), angle(_angle) {}
 
-
-
 ///////////////////////////////// Range /////////////////////////////////
 
 inline
@@ -2085,6 +2144,36 @@ Scalar_<_Tp>::Scalar_(_Tp v0, _Tp v1, _Tp v2, _Tp v3)
     this->val[3] = v3;
 }
 
+template<typename _Tp> inline
+Scalar_<_Tp>::Scalar_(const Scalar_<_Tp>& s) : Vec<_Tp, 4>(s) {
+}
+
+template<typename _Tp> inline
+Scalar_<_Tp>::Scalar_(Scalar_<_Tp>&& s) noexcept {
+    this->val[0] = std::move(s.val[0]);
+    this->val[1] = std::move(s.val[1]);
+    this->val[2] = std::move(s.val[2]);
+    this->val[3] = std::move(s.val[3]);
+}
+
+template<typename _Tp> inline
+Scalar_<_Tp>& Scalar_<_Tp>::operator=(const Scalar_<_Tp>& s) {
+    this->val[0] = s.val[0];
+    this->val[1] = s.val[1];
+    this->val[2] = s.val[2];
+    this->val[3] = s.val[3];
+    return *this;
+}
+
+template<typename _Tp> inline
+Scalar_<_Tp>& Scalar_<_Tp>::operator=(Scalar_<_Tp>&& s) noexcept {
+    this->val[0] = std::move(s.val[0]);
+    this->val[1] = std::move(s.val[1]);
+    this->val[2] = std::move(s.val[2]);
+    this->val[3] = std::move(s.val[3]);
+    return *this;
+}
+
 template<typename _Tp> template<typename _Tp2, int cn> inline
 Scalar_<_Tp>::Scalar_(const Vec<_Tp2, cn>& v)
 {