Skip to main content
Code Review

Return to Answer

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link
  • ByDistance looks very ad-hoc. If you move dist to Point (where it really belongs) as a member function, ByDistance is not required at all, e.g:

     temp.erase(remove_if(temp.begin(), 
     temp.end(),
     [&reference, distanceThreshold](Point& p){
     return reference.dist(p > distanceThreshold;
     }),
     temp.end());
    

    and

     sort(temp.begin(), temp.end(),
     [&reference](const Point& p1, const Point& p2) {
     return reference.dist(p1) < reference.dist(p2);
     });
     );
    
  • I don't see a need to create yet another vector with

     vector<Point> result(sz);
    

    You may reuse temp with temp.resize() instead.

  • Mandatory advisory against using namespace std using namespace std.

  • ByDistance looks very ad-hoc. If you move dist to Point (where it really belongs) as a member function, ByDistance is not required at all, e.g:

     temp.erase(remove_if(temp.begin(), 
     temp.end(),
     [&reference, distanceThreshold](Point& p){
     return reference.dist(p > distanceThreshold;
     }),
     temp.end());
    

    and

     sort(temp.begin(), temp.end(),
     [&reference](const Point& p1, const Point& p2) {
     return reference.dist(p1) < reference.dist(p2);
     });
     );
    
  • I don't see a need to create yet another vector with

     vector<Point> result(sz);
    

    You may reuse temp with temp.resize() instead.

  • Mandatory advisory against using namespace std.

  • ByDistance looks very ad-hoc. If you move dist to Point (where it really belongs) as a member function, ByDistance is not required at all, e.g:

     temp.erase(remove_if(temp.begin(), 
     temp.end(),
     [&reference, distanceThreshold](Point& p){
     return reference.dist(p > distanceThreshold;
     }),
     temp.end());
    

    and

     sort(temp.begin(), temp.end(),
     [&reference](const Point& p1, const Point& p2) {
     return reference.dist(p1) < reference.dist(p2);
     });
     );
    
  • I don't see a need to create yet another vector with

     vector<Point> result(sz);
    

    You may reuse temp with temp.resize() instead.

  • Mandatory advisory against using namespace std.

Source Link
vnp
  • 58.6k
  • 4
  • 55
  • 144
  • ByDistance looks very ad-hoc. If you move dist to Point (where it really belongs) as a member function, ByDistance is not required at all, e.g:

     temp.erase(remove_if(temp.begin(), 
     temp.end(),
     [&reference, distanceThreshold](Point& p){
     return reference.dist(p > distanceThreshold;
     }),
     temp.end());
    

    and

     sort(temp.begin(), temp.end(),
     [&reference](const Point& p1, const Point& p2) {
     return reference.dist(p1) < reference.dist(p2);
     });
     );
    
  • I don't see a need to create yet another vector with

     vector<Point> result(sz);
    

    You may reuse temp with temp.resize() instead.

  • Mandatory advisory against using namespace std.

lang-cpp

AltStyle によって変換されたページ (->オリジナル) /