From ca51f9eb4a576f6b5eaf636936f0bfe958dc9b6e Mon Sep 17 00:00:00 2001 From: Felipe Lema <1232306+FelipeLema@users.noreply.github.com> Date: Mon, 12 Apr 2021 14:32:54 -0400 Subject: [PATCH] use tuple for lexicographical comparison --- src/position.hh | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/position.hh b/src/position.hh index fd953cb2..250cdead 100644 --- a/src/position.hh +++ b/src/position.hh @@ -23,14 +23,23 @@ struct Pos { // Compare two Positions and check if they are equal. Ignores the value of // |interesting|. bool operator==(const Pos &o) const { - return line == o.line && column == o.column; + return asTuple() == o.asTuple(); } bool operator<(const Pos &o) const { - if (line != o.line) - return line < o.line; - return column < o.column; + return asTuple() < o.asTuple(); } - bool operator<=(const Pos &o) const { return !(o < *this); } + bool operator<=(const Pos &o) const { + return asTuple() <= o.asTuple(); + } +protected: + /*! + * (line, pos) + * use for lexicographic comparison + */ + auto asTuple() const -> std::tuple { + return std::make_tuple(line, tuple); + } + }; struct Range {