In general, the implementation of comparison operators (and functions) for several fields is more clearly expressed in terms of tie , when a lexicographic is required to be ordered .
static bool compare(Node const& l, Node const& r) {
However, even this leaves some duplication and a path to inconsistency. The following assistant sees the following:
static std::tuple<int&,int&> tuplize(Node const& n) { return std::tie(ny, nx); }
which can then be applied simply:
static bool compare(Node const& l, Node const& r) { return tuplize(l) < tuplize(r); }
Taaadaaam :)
Matthieu M.
source share