From 4fd0e5ca31f96015855447582af7ad84303604f7 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Tue, 2 Feb 2021 10:11:42 +0000 Subject: [PATCH 1/6] Add equal_to, minus, multiplies to CGAL::Kernel_d with a nested result_type --- Kernel_d/include/CGAL/Kernel_d/Iso_box_d.h | 39 ++++++++++++++++++++-- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/Kernel_d/include/CGAL/Kernel_d/Iso_box_d.h b/Kernel_d/include/CGAL/Kernel_d/Iso_box_d.h index 3794119da67..addd748e2a6 100644 --- a/Kernel_d/include/CGAL/Kernel_d/Iso_box_d.h +++ b/Kernel_d/include/CGAL/Kernel_d/Iso_box_d.h @@ -32,6 +32,39 @@ namespace CGAL { struct Begin {}; struct End {}; struct Cartesian_end {}; + + template + struct equal_to { + typedef bool result_type; + + bool operator()(const T &lhs, const T &rhs) const + { + return lhs == rhs; + } + + }; + + template + struct minus { + typedef bool result_type; + + T operator()(const T &lhs, const T &rhs) const + { + return lhs - rhs; + } + + }; + + template + struct multiplies { + typedef bool result_type; + + T operator()(const T &lhs, const T &rhs) const + { + return lhs * rhs; + } + + }; } // namespace Kernel_d template < typename Point_, typename Functor_ > @@ -277,11 +310,11 @@ namespace CGAL { RT volume_nominator() const { - typedef typename CIRT::template Iterator >::type + typedef typename CIRT::template Iterator >::type Iter; Iter b(ptr()->upper, ptr()->lower, Begin()); Iter e(ptr()->upper, ptr()->lower, Cartesian_end()); - return std::accumulate(b, e, RT(1), std::multiplies()); + return std::accumulate(b, e, RT(1), Kernel_d::multiplies()); } RT volume_denominator() const @@ -373,7 +406,7 @@ public: bool is_degenerate() const { typedef typename CIRT:: - template Iterator >::type Iter; + template Iterator >::type Iter; // omit homogenizing coordinates Iter e(ptr()->lower, ptr()->upper, Cartesian_end()); return From 9e9e48538726bb9ef77d962aa786601a4569627b Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Tue, 2 Feb 2021 11:19:53 +0000 Subject: [PATCH 2/6] Fix result_type --- Kernel_d/include/CGAL/Kernel_d/Iso_box_d.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Kernel_d/include/CGAL/Kernel_d/Iso_box_d.h b/Kernel_d/include/CGAL/Kernel_d/Iso_box_d.h index addd748e2a6..3b4c46fadc4 100644 --- a/Kernel_d/include/CGAL/Kernel_d/Iso_box_d.h +++ b/Kernel_d/include/CGAL/Kernel_d/Iso_box_d.h @@ -46,7 +46,7 @@ namespace CGAL { template struct minus { - typedef bool result_type; + typedef T result_type; T operator()(const T &lhs, const T &rhs) const { @@ -57,7 +57,7 @@ namespace CGAL { template struct multiplies { - typedef bool result_type; + typedef T result_type; T operator()(const T &lhs, const T &rhs) const { From a1189511f922abf81fb260892b10cd1306588aad Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Wed, 3 Feb 2021 09:10:59 +0000 Subject: [PATCH 3/6] No need for multiplies --- Kernel_d/include/CGAL/Kernel_d/Iso_box_d.h | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/Kernel_d/include/CGAL/Kernel_d/Iso_box_d.h b/Kernel_d/include/CGAL/Kernel_d/Iso_box_d.h index 3b4c46fadc4..2f150262095 100644 --- a/Kernel_d/include/CGAL/Kernel_d/Iso_box_d.h +++ b/Kernel_d/include/CGAL/Kernel_d/Iso_box_d.h @@ -37,7 +37,7 @@ namespace CGAL { struct equal_to { typedef bool result_type; - bool operator()(const T &lhs, const T &rhs) const + result_type operator()(const T &lhs, const T &rhs) const { return lhs == rhs; } @@ -48,23 +48,13 @@ namespace CGAL { struct minus { typedef T result_type; - T operator()(const T &lhs, const T &rhs) const + result_type operator()(const T &lhs, const T &rhs) const { return lhs - rhs; } }; - template - struct multiplies { - typedef T result_type; - - T operator()(const T &lhs, const T &rhs) const - { - return lhs * rhs; - } - - }; } // namespace Kernel_d template < typename Point_, typename Functor_ > @@ -314,7 +304,7 @@ namespace CGAL { Iter; Iter b(ptr()->upper, ptr()->lower, Begin()); Iter e(ptr()->upper, ptr()->lower, Cartesian_end()); - return std::accumulate(b, e, RT(1), Kernel_d::multiplies()); + return std::accumulate(b, e, RT(1), std::multiplies()); } RT volume_denominator() const From 75bdca5e9fedfe2f5404029df082c73887cf6db5 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Wed, 3 Feb 2021 09:31:33 +0000 Subject: [PATCH 4/6] Use solution which does not depend on result_type as proposedby Laurent --- Kernel_d/include/CGAL/Kernel_d/Iso_box_d.h | 36 ++++++---------------- 1 file changed, 10 insertions(+), 26 deletions(-) diff --git a/Kernel_d/include/CGAL/Kernel_d/Iso_box_d.h b/Kernel_d/include/CGAL/Kernel_d/Iso_box_d.h index 2f150262095..3964fa2ada7 100644 --- a/Kernel_d/include/CGAL/Kernel_d/Iso_box_d.h +++ b/Kernel_d/include/CGAL/Kernel_d/Iso_box_d.h @@ -25,6 +25,7 @@ #include #include #include +#include namespace CGAL { @@ -32,29 +33,6 @@ namespace CGAL { struct Begin {}; struct End {}; struct Cartesian_end {}; - - template - struct equal_to { - typedef bool result_type; - - result_type operator()(const T &lhs, const T &rhs) const - { - return lhs == rhs; - } - - }; - - template - struct minus { - typedef T result_type; - - result_type operator()(const T &lhs, const T &rhs) const - { - return lhs - rhs; - } - - }; - } // namespace Kernel_d template < typename Point_, typename Functor_ > @@ -64,7 +42,13 @@ namespace CGAL { typedef typename Point::Cartesian_const_iterator Iterator; typedef Cartesian_iterator Self; - typedef typename Functor::result_type value_type; + + typedef typename std::iterator_traits::value_type + Coordinate_type; + + typedef decltype( + std::declval()(std::declval(), + std::declval())) value_type; typedef value_type& reference; typedef value_type* pointer; typedef std::ptrdiff_t difference_type; @@ -300,7 +284,7 @@ namespace CGAL { RT volume_nominator() const { - typedef typename CIRT::template Iterator >::type + typedef typename CIRT::template Iterator >::type Iter; Iter b(ptr()->upper, ptr()->lower, Begin()); Iter e(ptr()->upper, ptr()->lower, Cartesian_end()); @@ -396,7 +380,7 @@ public: bool is_degenerate() const { typedef typename CIRT:: - template Iterator >::type Iter; + template Iterator >::type Iter; // omit homogenizing coordinates Iter e(ptr()->lower, ptr()->upper, Cartesian_end()); return From 21cda32aef14a14d9b34d1bd3546131859398efa Mon Sep 17 00:00:00 2001 From: Laurent Rineau Date: Tue, 9 Feb 2021 09:27:02 +0100 Subject: [PATCH 5/6] Simplify `value_type` and change `reference` --- Kernel_d/include/CGAL/Kernel_d/Iso_box_d.h | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/Kernel_d/include/CGAL/Kernel_d/Iso_box_d.h b/Kernel_d/include/CGAL/Kernel_d/Iso_box_d.h index 3964fa2ada7..402ef35b8f5 100644 --- a/Kernel_d/include/CGAL/Kernel_d/Iso_box_d.h +++ b/Kernel_d/include/CGAL/Kernel_d/Iso_box_d.h @@ -42,15 +42,11 @@ namespace CGAL { typedef typename Point::Cartesian_const_iterator Iterator; typedef Cartesian_iterator Self; - - typedef typename std::iterator_traits::value_type - Coordinate_type; - - typedef decltype( - std::declval()(std::declval(), - std::declval())) value_type; - typedef value_type& reference; - typedef value_type* pointer; + typedef decltype(std::declval()( + *std::declval(), + *std::declval())) value_type; + typedef value_type reference; + typedef const value_type* pointer; typedef std::ptrdiff_t difference_type; typedef std::input_iterator_tag iterator_category; @@ -96,7 +92,7 @@ namespace CGAL { return tmp; } - value_type operator*() const { return f(*pb, *qb); } + reference operator*() const { return f(*pb, *qb); } pointer operator->() const { return &(**this); } const Functor& functor() const { return f; } From ab5517e1acb494cba28496a07437be9a7af2a39d Mon Sep 17 00:00:00 2001 From: Laurent Rineau Date: Tue, 9 Feb 2021 09:27:30 +0100 Subject: [PATCH 6/6] Apply the same for Homogeneous_iterator --- Kernel_d/include/CGAL/Kernel_d/Iso_box_d.h | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Kernel_d/include/CGAL/Kernel_d/Iso_box_d.h b/Kernel_d/include/CGAL/Kernel_d/Iso_box_d.h index 402ef35b8f5..12ff9aeb723 100644 --- a/Kernel_d/include/CGAL/Kernel_d/Iso_box_d.h +++ b/Kernel_d/include/CGAL/Kernel_d/Iso_box_d.h @@ -121,9 +121,12 @@ namespace CGAL { typedef typename Point::Homogeneous_const_iterator Iterator; typedef Homogeneous_iterator Self; - typedef typename Functor::result_type value_type; - typedef value_type& reference; - typedef value_type* pointer; + typedef typename Kernel_traits::Kernel::RT RT; + typedef decltype(std::declval()( + *std::declval() * std::declval(), + *std::declval() * std::declval())) value_type; + typedef value_type reference; + typedef const value_type* pointer; typedef std::ptrdiff_t difference_type; typedef std::input_iterator_tag iterator_category; @@ -131,7 +134,6 @@ namespace CGAL { Iterator pb, qb; Functor f; - typedef typename Kernel_traits::Kernel::RT RT; RT hp, hq; // homogenizing coordinates public: @@ -280,7 +282,7 @@ namespace CGAL { RT volume_nominator() const { - typedef typename CIRT::template Iterator >::type + typedef typename CIRT::template Iterator >::type Iter; Iter b(ptr()->upper, ptr()->lower, Begin()); Iter e(ptr()->upper, ptr()->lower, Cartesian_end());