From c4ad713b9ef080d8c376489a1bba6e12c98c3446 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Tue, 5 Jan 2021 11:40:22 +0100 Subject: [PATCH] replace bind in Convex_hull_2 --- .../Convex_hull_2/ch_graham_anderson.cpp | 3 +- .../Convex_hull_2/ch_akl_toussaint_impl.h | 7 ++-- .../CGAL/Convex_hull_2/ch_bykat_impl.h | 33 +++++++++++-------- .../include/CGAL/Convex_hull_2/ch_eddy_impl.h | 19 +++++++---- .../CGAL/Convex_hull_2/ch_jarvis_impl.h | 7 ++-- 5 files changed, 41 insertions(+), 28 deletions(-) diff --git a/Convex_hull_2/examples/Convex_hull_2/ch_graham_anderson.cpp b/Convex_hull_2/examples/Convex_hull_2/ch_graham_anderson.cpp index bc98d8c91ed..cc50d5f5c1b 100644 --- a/Convex_hull_2/examples/Convex_hull_2/ch_graham_anderson.cpp +++ b/Convex_hull_2/examples/Convex_hull_2/ch_graham_anderson.cpp @@ -2,7 +2,6 @@ #include #include #include -#include typedef CGAL::Exact_predicates_inexact_constructions_kernel K; @@ -23,7 +22,7 @@ ch_graham_anderson( InputIterator first, InputIterator beyond, std::vector< Point_2 > V (first, beyond); typename std::vector< Point_2 >::iterator it = std::min_element(V.begin(), V.end(), Less_xy_2()); - std::sort( V.begin(), V.end(), boost::bind(Less_rotate_ccw_2(), *it, _1, _2) ); + std::sort( V.begin(), V.end(), [it](const Point_2& p1, const Point_2& p2){return Less_rotate_ccw_2()(*it, p1, p2);} ); if ( *(V.begin()) != *(V.rbegin()) ) { result = CGAL::ch_graham_andrew_scan( V.begin(), V.end(), result, ch_traits); diff --git a/Convex_hull_2/include/CGAL/Convex_hull_2/ch_akl_toussaint_impl.h b/Convex_hull_2/include/CGAL/Convex_hull_2/ch_akl_toussaint_impl.h index c06435efcef..0fdc1a0367b 100644 --- a/Convex_hull_2/include/CGAL/Convex_hull_2/ch_akl_toussaint_impl.h +++ b/Convex_hull_2/include/CGAL/Convex_hull_2/ch_akl_toussaint_impl.h @@ -25,7 +25,6 @@ #include #include #include -#include #include #include #include @@ -296,9 +295,11 @@ ch_akl_toussaint(ForwardIterator first, ForwardIterator last, std::sort( std::next(region2.begin() ), region2.end(), ch_traits.less_xy_2_object() ); std::sort( std::next(region3.begin() ), region3.end(), - boost::bind(ch_traits.less_xy_2_object(), _2, _1) ); + [&ch_traits](const Point_2& p1, const Point_2& p2) + { return ch_traits.less_xy_2_object()(p2, p1); }); std::sort( std::next(region4.begin() ), region4.end(), - boost::bind(ch_traits.less_xy_2_object(), _2, _1) ); + [&ch_traits](const Point_2& p1, const Point_2& p2) + { return ch_traits.less_xy_2_object()(p2, p1); }); if (! equal_points(*w,*s) ) { diff --git a/Convex_hull_2/include/CGAL/Convex_hull_2/ch_bykat_impl.h b/Convex_hull_2/include/CGAL/Convex_hull_2/ch_bykat_impl.h index 32334e4e7f9..0b4ae797fb3 100644 --- a/Convex_hull_2/include/CGAL/Convex_hull_2/ch_bykat_impl.h +++ b/Convex_hull_2/include/CGAL/Convex_hull_2/ch_bykat_impl.h @@ -26,7 +26,6 @@ #include #include #include -#include namespace CGAL { template @@ -77,18 +76,21 @@ ch_bykat(InputIterator first, InputIterator last, H.push_back( a ); L.push_back( P.begin() ); R.push_back( l = std::partition(P.begin(), P.end(), - boost::bind(left_turn, boost::cref(a), boost::cref(b), _1))); - r = std::partition( l, P.end(), boost::bind(left_turn, boost::cref(b), boost::cref(a), _1)); + [&left_turn, &a, &b](const Point_2& p){ return left_turn(a,b,p); }) ); + r = std::partition( l, P.end(), [&left_turn, &a, &b](const Point_2& p){ return left_turn(b,a,p); }); for (;;) { if ( l != r) { - Point_2 c = *std::min_element( l, r, boost::bind(less_dist, boost::cref(a), boost::cref(b), _1, _2)); + Point_2 c = *std::min_element( l, r, [&less_dist,&a,&b](const Point_2&p1, const Point_2& p2) + { return less_dist(a, b, p1, p2); }); H.push_back( b ); L.push_back( l ); - R.push_back( l = std::partition(l, r, boost::bind(left_turn, boost::cref(b), boost::cref(c), _1))); - r = std::partition(l, r, boost::bind(left_turn, boost::cref(c), boost::cref(a), _1)); + R.push_back( l = std::partition(l, r, [&left_turn,&c,&b](const Point_2&p) + { return left_turn(b, c, p); })); + r = std::partition(l, r, [&left_turn,&c,&a](const Point_2&p) + { return left_turn(c, a, p); }); b = c; } else @@ -173,8 +175,10 @@ ch_bykat_with_threshold(InputIterator first, InputIterator last, H.push_back( a ); L.push_back( Pbegin ); Left_turn_2 left_turn = ch_traits.left_turn_2_object(); - R.push_back( l = std::partition( Pbegin, Pend, boost::bind(left_turn, boost::cref(a), boost::cref(b), _1))); - r = std::partition( l, Pend, boost::bind(left_turn, boost::cref(b), boost::cref(a), _1)); + R.push_back( l = std::partition( Pbegin, Pend, [&left_turn,&a,&b](const Point_2&p) + { return left_turn(a, b, p); })); + r = std::partition( l, Pend, [&left_turn,&a,&b](const Point_2&p) + { return left_turn(b, a, p); }); Less_dist less_dist = ch_traits.less_signed_distance_to_line_2_object(); for (;;) @@ -183,11 +187,14 @@ ch_bykat_with_threshold(InputIterator first, InputIterator last, { if ( r-l > CGAL_ch_THRESHOLD ) { - Point_2 c = *std::min_element( l, r, boost::bind(less_dist, boost::cref(a), boost::cref(b), _1, _2)); + Point_2 c = *std::min_element( l, r, [&less_dist,&a,&b](const Point_2&p1, const Point_2& p2) + { return less_dist(a, b, p1, p2); }); H.push_back( b ); L.push_back( l ); - R.push_back( l = std::partition(l, r, boost::bind(left_turn, boost::cref(b), boost::cref(c), _1))); - r = std::partition(l, r, boost::bind(left_turn, boost::cref(c), boost::cref(a), _1)); + R.push_back( l = std::partition(l, r, [&left_turn,&c,&b](const Point_2&p) + { return left_turn(b, c, p); })); + r = std::partition(l, r, [&left_turn,&a,&c](const Point_2&p) + { return left_turn(c, a, p); }); b = c; } else @@ -201,8 +208,8 @@ ch_bykat_with_threshold(InputIterator first, InputIterator last, } else { - std::sort(std::next(l), r, - boost::bind(ch_traits.less_xy_2_object(), _2, _1) ); + std::sort(std::next(l), r, [&ch_traits](const Point_2&p1, const Point_2& p2) + { return ch_traits.less_xy_2_object()(p2, p1); }); } ch__ref_graham_andrew_scan(l, std::next(r), res, ch_traits); std::swap( a, *l); diff --git a/Convex_hull_2/include/CGAL/Convex_hull_2/ch_eddy_impl.h b/Convex_hull_2/include/CGAL/Convex_hull_2/ch_eddy_impl.h index 2a7b29c2ddd..19df2467657 100644 --- a/Convex_hull_2/include/CGAL/Convex_hull_2/ch_eddy_impl.h +++ b/Convex_hull_2/include/CGAL/Convex_hull_2/ch_eddy_impl.h @@ -25,7 +25,6 @@ #include #include #include -#include namespace CGAL { @@ -45,7 +44,8 @@ ch__recursive_eddy(List& L, CGAL_ch_precondition( \ std::find_if(a_it, b_it, \ - boost::bind(left_turn, *b_it, *a_it, _1)) \ + [&left_turn, a_it, b_it](const Point_2& p) + { return left_turn(*b_it, *a_it, p); }) \ != b_it ); @@ -53,11 +53,14 @@ ch__recursive_eddy(List& L, Less_dist less_dist = ch_traits.less_signed_distance_to_line_2_object(); ListIterator c_it = std::min_element( f_it, b_it, // max before - boost::bind(less_dist, *a_it, *b_it, _1, _2)); + [&less_dist, a_it, b_it](const Point_2& p1, const Point_2& p2) + { return less_dist(*a_it, *b_it, p1, p2); }); Point_2 c = *c_it; - c_it = std::partition(f_it, b_it, boost::bind(left_turn, c, *a_it, _1)); - f_it = std::partition(c_it, b_it, boost::bind(left_turn, *b_it, c, _1)); + c_it = std::partition(f_it, b_it, [&left_turn, &c, a_it](const Point_2& p) + {return left_turn(c, *a_it, p);}); + f_it = std::partition(c_it, b_it, [&left_turn, &c, b_it](const Point_2& p) + {return left_turn(*b_it, c, p);}); c_it = L.insert(c_it, c); L.erase( f_it, b_it ); @@ -104,7 +107,8 @@ ch_eddy(InputIterator first, InputIterator last, L.erase(e); e = std::partition(L.begin(), L.end(), - boost::bind(left_turn, ep, wp, _1) ); + [&left_turn, &wp, &ep](const Point_2& p) + {return left_turn(ep, wp, p);} ); L.push_front(wp); e = L.insert(e, ep); @@ -112,7 +116,8 @@ ch_eddy(InputIterator first, InputIterator last, { ch__recursive_eddy( L, L.begin(), e, ch_traits); } - w = std::find_if( e, L.end(), boost::bind(left_turn, wp, ep, _1) ); + w = std::find_if( e, L.end(), [&left_turn, &wp, &ep](const Point_2& p) + { return left_turn(wp, ep, p); }); if ( w == L.end() ) { L.erase( ++e, L.end() ); diff --git a/Convex_hull_2/include/CGAL/Convex_hull_2/ch_jarvis_impl.h b/Convex_hull_2/include/CGAL/Convex_hull_2/ch_jarvis_impl.h index c5d3309cbd0..65b2d1fc29c 100644 --- a/Convex_hull_2/include/CGAL/Convex_hull_2/ch_jarvis_impl.h +++ b/Convex_hull_2/include/CGAL/Convex_hull_2/ch_jarvis_impl.h @@ -24,7 +24,6 @@ #include #include #include -#include namespace CGAL { @@ -65,7 +64,8 @@ ch_jarvis_march(ForwardIterator first, ForwardIterator last, Point previous_point = start_p; ) ForwardIterator it = std::min_element( first, last, - boost::bind(rotation_predicate, boost::cref(start_p), _1, _2) ); + [&start_p, &rotation_predicate](const Point& p1, const Point& p2) + {return rotation_predicate(start_p, p1, p2);} ); while (! equal_points(*it, stop_p) ) { CGAL_ch_exactness_assertion( \ @@ -80,7 +80,8 @@ ch_jarvis_march(ForwardIterator first, ForwardIterator last, constructed_points <= count_points + 1 ); it = std::min_element( first, last, - boost::bind(rotation_predicate, *it, _1, _2) ); + [it, &rotation_predicate](const Point& p1, const Point& p2) + {return rotation_predicate(*it, p1, p2);} ); } CGAL_ch_postcondition( \ is_ccw_strongly_convex_2( res.output_so_far_begin(), \