Skip to content

Commit eab2b9d

Browse files
committed
core: ensure is_trivially_copyable for simple types
1 parent 13c6eb4 commit eab2b9d

2 files changed

Lines changed: 39 additions & 110 deletions

File tree

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

Lines changed: 16 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,13 @@ template<typename _Tp> class Point_
162162
//! default constructor
163163
Point_();
164164
Point_(_Tp _x, _Tp _y);
165-
Point_(const Point_& pt);
166-
Point_(Point_&& pt) CV_NOEXCEPT;
165+
Point_(const Point_& pt) = default;
166+
Point_(Point_&& pt) CV_NOEXCEPT = default;
167167
Point_(const Size_<_Tp>& sz);
168168
Point_(const Vec<_Tp, 2>& v);
169169

170-
Point_& operator = (const Point_& pt);
171-
Point_& operator = (Point_&& pt) CV_NOEXCEPT;
170+
Point_& operator = (const Point_& pt) = default;
171+
Point_& operator = (Point_&& pt) CV_NOEXCEPT = default;
172172
//! conversion to another data type
173173
template<typename _Tp2> operator Point_<_Tp2>() const;
174174

@@ -244,13 +244,13 @@ template<typename _Tp> class Point3_
244244
//! default constructor
245245
Point3_();
246246
Point3_(_Tp _x, _Tp _y, _Tp _z);
247-
Point3_(const Point3_& pt);
248-
Point3_(Point3_&& pt) CV_NOEXCEPT;
247+
Point3_(const Point3_& pt) = default;
248+
Point3_(Point3_&& pt) CV_NOEXCEPT = default;
249249
explicit Point3_(const Point_<_Tp>& pt);
250250
Point3_(const Vec<_Tp, 3>& v);
251251

252-
Point3_& operator = (const Point3_& pt);
253-
Point3_& operator = (Point3_&& pt) CV_NOEXCEPT;
252+
Point3_& operator = (const Point3_& pt) = default;
253+
Point3_& operator = (Point3_&& pt) CV_NOEXCEPT = default;
254254
//! conversion to another data type
255255
template<typename _Tp2> operator Point3_<_Tp2>() const;
256256
//! conversion to cv::Vec<>
@@ -320,12 +320,12 @@ template<typename _Tp> class Size_
320320
//! default constructor
321321
Size_();
322322
Size_(_Tp _width, _Tp _height);
323-
Size_(const Size_& sz);
324-
Size_(Size_&& sz) CV_NOEXCEPT;
323+
Size_(const Size_& sz) = default;
324+
Size_(Size_&& sz) CV_NOEXCEPT = default;
325325
Size_(const Point_<_Tp>& pt);
326326

327-
Size_& operator = (const Size_& sz);
328-
Size_& operator = (Size_&& sz) CV_NOEXCEPT;
327+
Size_& operator = (const Size_& sz) = default;
328+
Size_& operator = (Size_&& sz) CV_NOEXCEPT = default;
329329
//! the area (width*height)
330330
_Tp area() const;
331331
//! aspect ratio (width/height)
@@ -425,13 +425,13 @@ template<typename _Tp> class Rect_
425425
//! default constructor
426426
Rect_();
427427
Rect_(_Tp _x, _Tp _y, _Tp _width, _Tp _height);
428-
Rect_(const Rect_& r);
429-
Rect_(Rect_&& r) CV_NOEXCEPT;
428+
Rect_(const Rect_& r) = default;
429+
Rect_(Rect_&& r) CV_NOEXCEPT = default;
430430
Rect_(const Point_<_Tp>& org, const Size_<_Tp>& sz);
431431
Rect_(const Point_<_Tp>& pt1, const Point_<_Tp>& pt2);
432432

433-
Rect_& operator = ( const Rect_& r );
434-
Rect_& operator = ( Rect_&& r ) CV_NOEXCEPT;
433+
Rect_& operator = (const Rect_& r) = default;
434+
Rect_& operator = (Rect_&& r) CV_NOEXCEPT = default;
435435
//! the top-left corner
436436
Point_<_Tp> tl() const;
437437
//! the bottom-right corner
@@ -1164,14 +1164,6 @@ template<typename _Tp> inline
11641164
Point_<_Tp>::Point_(_Tp _x, _Tp _y)
11651165
: x(_x), y(_y) {}
11661166

1167-
template<typename _Tp> inline
1168-
Point_<_Tp>::Point_(const Point_& pt)
1169-
: x(pt.x), y(pt.y) {}
1170-
1171-
template<typename _Tp> inline
1172-
Point_<_Tp>::Point_(Point_&& pt) CV_NOEXCEPT
1173-
: x(std::move(pt.x)), y(std::move(pt.y)) {}
1174-
11751167
template<typename _Tp> inline
11761168
Point_<_Tp>::Point_(const Size_<_Tp>& sz)
11771169
: x(sz.width), y(sz.height) {}
@@ -1180,20 +1172,6 @@ template<typename _Tp> inline
11801172
Point_<_Tp>::Point_(const Vec<_Tp,2>& v)
11811173
: x(v[0]), y(v[1]) {}
11821174

1183-
template<typename _Tp> inline
1184-
Point_<_Tp>& Point_<_Tp>::operator = (const Point_& pt)
1185-
{
1186-
x = pt.x; y = pt.y;
1187-
return *this;
1188-
}
1189-
1190-
template<typename _Tp> inline
1191-
Point_<_Tp>& Point_<_Tp>::operator = (Point_&& pt) CV_NOEXCEPT
1192-
{
1193-
x = std::move(pt.x); y = std::move(pt.y);
1194-
return *this;
1195-
}
1196-
11971175
template<typename _Tp> template<typename _Tp2> inline
11981176
Point_<_Tp>::operator Point_<_Tp2>() const
11991177
{
@@ -1431,14 +1409,6 @@ template<typename _Tp> inline
14311409
Point3_<_Tp>::Point3_(_Tp _x, _Tp _y, _Tp _z)
14321410
: x(_x), y(_y), z(_z) {}
14331411

1434-
template<typename _Tp> inline
1435-
Point3_<_Tp>::Point3_(const Point3_& pt)
1436-
: x(pt.x), y(pt.y), z(pt.z) {}
1437-
1438-
template<typename _Tp> inline
1439-
Point3_<_Tp>::Point3_(Point3_&& pt) CV_NOEXCEPT
1440-
: x(std::move(pt.x)), y(std::move(pt.y)), z(std::move(pt.z)) {}
1441-
14421412
template<typename _Tp> inline
14431413
Point3_<_Tp>::Point3_(const Point_<_Tp>& pt)
14441414
: x(pt.x), y(pt.y), z(_Tp()) {}
@@ -1459,20 +1429,6 @@ Point3_<_Tp>::operator Vec<_Tp, 3>() const
14591429
return Vec<_Tp, 3>(x, y, z);
14601430
}
14611431

1462-
template<typename _Tp> inline
1463-
Point3_<_Tp>& Point3_<_Tp>::operator = (const Point3_& pt)
1464-
{
1465-
x = pt.x; y = pt.y; z = pt.z;
1466-
return *this;
1467-
}
1468-
1469-
template<typename _Tp> inline
1470-
Point3_<_Tp>& Point3_<_Tp>::operator = (Point3_&& pt) CV_NOEXCEPT
1471-
{
1472-
x = std::move(pt.x); y = std::move(pt.y); z = std::move(pt.z);
1473-
return *this;
1474-
}
1475-
14761432
template<typename _Tp> inline
14771433
_Tp Point3_<_Tp>::dot(const Point3_& pt) const
14781434
{
@@ -1685,14 +1641,6 @@ template<typename _Tp> inline
16851641
Size_<_Tp>::Size_(_Tp _width, _Tp _height)
16861642
: width(_width), height(_height) {}
16871643

1688-
template<typename _Tp> inline
1689-
Size_<_Tp>::Size_(const Size_& sz)
1690-
: width(sz.width), height(sz.height) {}
1691-
1692-
template<typename _Tp> inline
1693-
Size_<_Tp>::Size_(Size_&& sz) CV_NOEXCEPT
1694-
: width(std::move(sz.width)), height(std::move(sz.height)) {}
1695-
16961644
template<typename _Tp> inline
16971645
Size_<_Tp>::Size_(const Point_<_Tp>& pt)
16981646
: width(pt.x), height(pt.y) {}
@@ -1703,20 +1651,6 @@ Size_<_Tp>::operator Size_<_Tp2>() const
17031651
return Size_<_Tp2>(saturate_cast<_Tp2>(width), saturate_cast<_Tp2>(height));
17041652
}
17051653

1706-
template<typename _Tp> inline
1707-
Size_<_Tp>& Size_<_Tp>::operator = (const Size_<_Tp>& sz)
1708-
{
1709-
width = sz.width; height = sz.height;
1710-
return *this;
1711-
}
1712-
1713-
template<typename _Tp> inline
1714-
Size_<_Tp>& Size_<_Tp>::operator = (Size_<_Tp>&& sz) CV_NOEXCEPT
1715-
{
1716-
width = std::move(sz.width); height = std::move(sz.height);
1717-
return *this;
1718-
}
1719-
17201654
template<typename _Tp> inline
17211655
_Tp Size_<_Tp>::area() const
17221656
{
@@ -1827,14 +1761,6 @@ template<typename _Tp> inline
18271761
Rect_<_Tp>::Rect_(_Tp _x, _Tp _y, _Tp _width, _Tp _height)
18281762
: x(_x), y(_y), width(_width), height(_height) {}
18291763

1830-
template<typename _Tp> inline
1831-
Rect_<_Tp>::Rect_(const Rect_<_Tp>& r)
1832-
: x(r.x), y(r.y), width(r.width), height(r.height) {}
1833-
1834-
template<typename _Tp> inline
1835-
Rect_<_Tp>::Rect_(Rect_<_Tp>&& r) CV_NOEXCEPT
1836-
: x(std::move(r.x)), y(std::move(r.y)), width(std::move(r.width)), height(std::move(r.height)) {}
1837-
18381764
template<typename _Tp> inline
18391765
Rect_<_Tp>::Rect_(const Point_<_Tp>& org, const Size_<_Tp>& sz)
18401766
: x(org.x), y(org.y), width(sz.width), height(sz.height) {}
@@ -1848,26 +1774,6 @@ Rect_<_Tp>::Rect_(const Point_<_Tp>& pt1, const Point_<_Tp>& pt2)
18481774
height = std::max(pt1.y, pt2.y) - y;
18491775
}
18501776

1851-
template<typename _Tp> inline
1852-
Rect_<_Tp>& Rect_<_Tp>::operator = ( const Rect_<_Tp>& r )
1853-
{
1854-
x = r.x;
1855-
y = r.y;
1856-
width = r.width;
1857-
height = r.height;
1858-
return *this;
1859-
}
1860-
1861-
template<typename _Tp> inline
1862-
Rect_<_Tp>& Rect_<_Tp>::operator = ( Rect_<_Tp>&& r ) CV_NOEXCEPT
1863-
{
1864-
x = std::move(r.x);
1865-
y = std::move(r.y);
1866-
width = std::move(r.width);
1867-
height = std::move(r.height);
1868-
return *this;
1869-
}
1870-
18711777
template<typename _Tp> inline
18721778
Point_<_Tp> Rect_<_Tp>::tl() const
18731779
{

modules/core/test/test_misc.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -798,4 +798,27 @@ TEST(Core_Allocation, alignedAllocation)
798798
}
799799
}
800800

801+
802+
#if !(defined(__GNUC__) && __GNUC__ < 5) // GCC 4.8 emits: 'is_trivially_copyable' is not a member of 'std'
803+
TEST(Core_Types, trivially_copyable)
804+
{
805+
EXPECT_TRUE(std::is_trivially_copyable<cv::Complexd>::value);
806+
EXPECT_TRUE(std::is_trivially_copyable<cv::Point>::value);
807+
EXPECT_TRUE(std::is_trivially_copyable<cv::Point3f>::value);
808+
EXPECT_TRUE(std::is_trivially_copyable<cv::Size>::value);
809+
EXPECT_TRUE(std::is_trivially_copyable<cv::Range>::value);
810+
EXPECT_TRUE(std::is_trivially_copyable<cv::Rect>::value);
811+
EXPECT_TRUE(std::is_trivially_copyable<cv::RotatedRect>::value);
812+
//EXPECT_TRUE(std::is_trivially_copyable<cv::Scalar>::value); // derived from Vec (Matx)
813+
}
814+
815+
TEST(Core_Types, trivially_copyable_extra)
816+
{
817+
EXPECT_TRUE(std::is_trivially_copyable<cv::KeyPoint>::value);
818+
EXPECT_TRUE(std::is_trivially_copyable<cv::DMatch>::value);
819+
EXPECT_TRUE(std::is_trivially_copyable<cv::TermCriteria>::value);
820+
EXPECT_TRUE(std::is_trivially_copyable<cv::Moments>::value);
821+
}
822+
#endif
823+
801824
}} // namespace

0 commit comments

Comments
 (0)