use tuple for lexicographical comparison

This commit is contained in:
Felipe Lema 2021-04-12 14:32:54 -04:00
parent a4de46b9a0
commit ca51f9eb4a

View File

@ -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<Line,Column> {
return std::make_tuple(line, tuple);
}
};
struct Range {