From 3ebe8839b6f99d424bce25825b209974142cd14f Mon Sep 17 00:00:00 2001 From: Marc Glisse Date: Sun, 1 Mar 2020 12:50:13 +0100 Subject: [PATCH] swap for Point_2 and Point_d and make the implementations more similar, in case someone wants to replace it with a macro at some point. --- Cartesian_kernel/include/CGAL/Cartesian/Point_2.h | 9 +++++++++ Cartesian_kernel/include/CGAL/Cartesian/Point_3.h | 3 ++- Cartesian_kernel/include/CGAL/Cartesian/Vector_2.h | 10 ++++++++++ Cartesian_kernel/include/CGAL/Cartesian/Vector_3.h | 3 ++- Kernel_23/include/CGAL/Point_2.h | 13 +++++++++++-- Kernel_23/include/CGAL/Point_3.h | 2 +- Kernel_23/include/CGAL/Vector_2.h | 13 +++++++++++-- Kernel_23/include/CGAL/Vector_3.h | 2 +- .../include/CGAL/NewKernel_d/Wrapper/Point_d.h | 12 ++++++++++-- 9 files changed, 57 insertions(+), 10 deletions(-) diff --git a/Cartesian_kernel/include/CGAL/Cartesian/Point_2.h b/Cartesian_kernel/include/CGAL/Cartesian/Point_2.h index 92985777bbb..028c772c102 100644 --- a/Cartesian_kernel/include/CGAL/Cartesian/Point_2.h +++ b/Cartesian_kernel/include/CGAL/Cartesian/Point_2.h @@ -50,6 +50,15 @@ public: PointC2(const FT &hx, const FT &hy, const FT &hw) : base(hx, hy, hw) {} + friend void swap(Self& a, Self& b) +#ifdef __cpp_lib_is_swappable + noexcept(std::is_nothrow_swappable_v) +#endif + { + using std::swap; + swap(a.base, b.base); + } + const FT& x() const { return base.x(); diff --git a/Cartesian_kernel/include/CGAL/Cartesian/Point_3.h b/Cartesian_kernel/include/CGAL/Cartesian/Point_3.h index 35abdde9a8c..b46ab99284b 100644 --- a/Cartesian_kernel/include/CGAL/Cartesian/Point_3.h +++ b/Cartesian_kernel/include/CGAL/Cartesian/Point_3.h @@ -24,6 +24,7 @@ namespace CGAL { template < class R_ > class PointC3 { + typedef PointC3 Self; typedef typename R_::Vector_3 Vector_3; typedef typename R_::Point_3 Point_3; typedef typename R_::Aff_transformation_3 Aff_transformation_3; @@ -47,7 +48,7 @@ public: PointC3(const FT &x, const FT &y, const FT &z, const FT &w) : base(x, y, z, w) {} - friend void swap(PointC3& a, PointC3& b) + friend void swap(Self& a, Self& b) #ifdef __cpp_lib_is_swappable noexcept(std::is_nothrow_swappable_v) #endif diff --git a/Cartesian_kernel/include/CGAL/Cartesian/Vector_2.h b/Cartesian_kernel/include/CGAL/Cartesian/Vector_2.h index 6331471dff7..01986b321a3 100644 --- a/Cartesian_kernel/include/CGAL/Cartesian/Vector_2.h +++ b/Cartesian_kernel/include/CGAL/Cartesian/Vector_2.h @@ -27,6 +27,7 @@ namespace CGAL { template < class R_ > class VectorC2 { + typedef VectorC2 Self; typedef typename R_::FT FT; typedef typename R_::Point_2 Point_2; typedef typename R_::Vector_2 Vector_2; @@ -55,6 +56,15 @@ public: : base( hw != FT(1) ? CGAL::make_array(hx/hw, hy/hw) : CGAL::make_array(hx, hy) ) {} + friend void swap(Self& a, Self& b) +#ifdef __cpp_lib_is_swappable + noexcept(std::is_nothrow_swappable_v) +#endif + { + using std::swap; + swap(a.base, b.base); + } + const FT & x() const { return CGAL::get_pointee_or_identity(base)[0]; diff --git a/Cartesian_kernel/include/CGAL/Cartesian/Vector_3.h b/Cartesian_kernel/include/CGAL/Cartesian/Vector_3.h index 9b6b7e1db96..72954931d0b 100644 --- a/Cartesian_kernel/include/CGAL/Cartesian/Vector_3.h +++ b/Cartesian_kernel/include/CGAL/Cartesian/Vector_3.h @@ -27,6 +27,7 @@ template < class R_ > class VectorC3 { // https://doc.cgal.org/latest/Manual/devman_code_format.html#secprogramming_conventions + typedef VectorC3 Self; typedef typename R_::FT FT_; typedef typename R_::Point_3 Point_3; typedef typename R_::Vector_3 Vector_3; @@ -70,7 +71,7 @@ public: : base( w != FT_(1) ? CGAL::make_array(x/w, y/w, z/w) : CGAL::make_array(x, y, z) ) {} - friend void swap(VectorC3& a, VectorC3& b) + friend void swap(Self& a, Self& b) #ifdef __cpp_lib_is_swappable noexcept(std::is_nothrow_swappable_v) #endif diff --git a/Kernel_23/include/CGAL/Point_2.h b/Kernel_23/include/CGAL/Point_2.h index a5b00bb1eb9..7358d0dc46b 100644 --- a/Kernel_23/include/CGAL/Point_2.h +++ b/Kernel_23/include/CGAL/Point_2.h @@ -48,12 +48,12 @@ public: typedef RPoint_2 Rep; typedef typename R_::Cartesian_const_iterator_2 Cartesian_const_iterator; - const Rep& rep() const + const Rep& rep() const noexcept { return *this; } - Rep& rep() + Rep& rep() noexcept { return *this; } @@ -84,6 +84,15 @@ public: : RPoint_2(typename R::Construct_point_2()(Return_base_tag(), hx, hy, hw)) {} + friend void swap(Self& a, Self& b) +#ifdef __cpp_lib_is_swappable + noexcept(std::is_nothrow_swappable_v) +#endif + { + using std::swap; + swap(a.rep(), b.rep()); + } + typename cpp11::result_of::type x() const { diff --git a/Kernel_23/include/CGAL/Point_3.h b/Kernel_23/include/CGAL/Point_3.h index 83f65b42b5a..01b07bd3e0e 100644 --- a/Kernel_23/include/CGAL/Point_3.h +++ b/Kernel_23/include/CGAL/Point_3.h @@ -81,7 +81,7 @@ public: : Rep(typename R::Construct_point_3()(Return_base_tag(), hx, hy, hz, hw)) {} - friend void swap(Point_3& a, Point_3& b) + friend void swap(Self& a, Self& b) #ifdef __cpp_lib_is_swappable noexcept(std::is_nothrow_swappable_v) #endif diff --git a/Kernel_23/include/CGAL/Vector_2.h b/Kernel_23/include/CGAL/Vector_2.h index 4f570ed6b02..67f07e5e3e6 100644 --- a/Kernel_23/include/CGAL/Vector_2.h +++ b/Kernel_23/include/CGAL/Vector_2.h @@ -54,12 +54,12 @@ public: typedef RVector_2 Rep; typedef typename R_::Cartesian_const_iterator_2 Cartesian_const_iterator; - const Rep& rep() const + const Rep& rep() const noexcept { return *this; } - Rep& rep() + Rep& rep() noexcept { return *this; } @@ -93,6 +93,15 @@ public: Vector_2(const RT &x, const RT &y, const RT &w) : RVector_2(typename R::Construct_vector_2()(Return_base_tag(), x,y,w)) {} + friend void swap(Self& a, Self& b) +#ifdef __cpp_lib_is_swappable + noexcept(std::is_nothrow_swappable_v) +#endif + { + using std::swap; + swap(a.rep(), b.rep()); + } + typename cpp11::result_of::type x() const diff --git a/Kernel_23/include/CGAL/Vector_3.h b/Kernel_23/include/CGAL/Vector_3.h index 2775aa4c13e..077da5d649d 100644 --- a/Kernel_23/include/CGAL/Vector_3.h +++ b/Kernel_23/include/CGAL/Vector_3.h @@ -93,7 +93,7 @@ public: Vector_3(const RT& x, const RT& y, const RT& z, const RT& w) : Rep(typename R::Construct_vector_3()(Return_base_tag(), x, y, z, w)) {} - friend void swap(Vector_3& a, Vector_3& b) + friend void swap(Self& a, Self& b) #ifdef __cpp_lib_is_swappable noexcept(std::is_nothrow_swappable_v) #endif diff --git a/NewKernel_d/include/CGAL/NewKernel_d/Wrapper/Point_d.h b/NewKernel_d/include/CGAL/NewKernel_d/Wrapper/Point_d.h index 404eca88bf3..5c0dce2db1f 100644 --- a/NewKernel_d/include/CGAL/NewKernel_d/Wrapper/Point_d.h +++ b/NewKernel_d/include/CGAL/NewKernel_d/Wrapper/Point_d.h @@ -51,12 +51,12 @@ public: typedef typename Get_type::type Rep; //typedef typename CGAL::decay::type>::type Cartesian_const_iterator; - const Rep& rep() const + const Rep& rep() const noexcept { return *this; } - Rep& rep() + Rep& rep() noexcept { return *this; } @@ -101,6 +101,14 @@ public: Point_d(Origin&& v) : Rep(CPBase()(std::move(v))) {} + friend void swap(Self& a, Self& b) +#ifdef __cpp_lib_is_swappable + noexcept(std::is_nothrow_swappable_v) +#endif + { + using std::swap; + swap(a.rep(), b.rep()); + } decltype(auto) cartesian(int i)const{ return CCBase()(rep(),i);