Comparison functions for 2D points I have the following class for 2D points:

class Point {
private:
    double _x, _y;

public:
    Point(double x, double y) : _x(x), _y(y);

    double x() const { return _x; }
    double y() const { return _y; }
};


I wanted to add a few comparison functions that compared objects of this class in different ways.

One of them is just a simple function:

/// Returns whether A has a smaller y-coordinate than B
/// (and smaller x-coordinate in case of equality).
bool yComp(const Point &amp;A, const Point &amp;B) {
    if (A.y() != B.y()) return A.y() &lt; B.y();
    return A.x() &lt; B.x();
}


The other is a struct with operator() defined on it:

struct angleComp {
    Point origin;
    angleComp(const Point &amp;P);
    bool operator()(const Point &amp;A, const Point &amp;B);
};

// Constructs a new angle comparison with P as origin
angleComp::angleComp(const Point &amp;P) : origin(P) {}

// Compares according to the angles that the lines joining each point
// to a given origin form with the x-axis.
bool angleComp::operator()(const Point &amp;A, const Point &amp;B) {
    GeometricVector u = A - origin, v = B - origin;
    return u.x()*u.x()*u.sqrNorm() &lt; v.x()*v.x()*v.sqrNorm();
}


Do I put the comparisons inside the class definition? The first function could be made a static method, but the problem is I can't put angleComp inside the class (as a static member) since one of its fields is of type Point itself, which would be an incomplete type (inside the class declaration). And I would prefer these comparison functions to be grouped together (instead of one being a static member, and the other being a top-level thing).

So, an alternative would be to put both outside the class, but to retain some grouping, putting all of them in a namespace:

namespace PointComp {
    bool yComp(const Point &amp;A, const Point &amp;B);

    struct angleComp {
        Point origin;
        angleComp(const Point &amp;P);
        bool operator()(const Point &amp;A, const Point &amp;B);
    };
}
The overall design seems a bit complicated to me. Setters and getters are often more of an hindrance than a real asset, and the benefits of having a simple struct should not be under-estimated. In particular, it reminds you that you don't have to encapsulate everything, and that defining functions at the point of use is often the most convenient way to proceed:

struct Point { float x, y; };

// ...

// here I need to compare points by y and then x
auto best = std::max_element(v.begin(), v.end(), [](auto point_a, auto point_b) {
    return std::tie(point_a.y, point_a.x) &lt; std::tie(point_b.y, point_b.x);
    //      -&gt; tie gives you the lexicographic comparison for free
});

// and there by angle with etc.
auto widest = std::max_element(v.begin(), v.end(), [origin](auto point_a, auto point_b) {
    // ...
});


In a nutshell, why having a namespace and custom classes where you can simply use a lambda?