From 187a99aba28929780ee9b79cb53f3bd5c6914876 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sat, 15 Oct 2011 04:42:28 +0000 Subject: [PATCH] LineAndColumn: add comparison operators --- src/line_and_column.hh | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/line_and_column.hh b/src/line_and_column.hh index 8c8c1603..17e4e8d2 100644 --- a/src/line_and_column.hh +++ b/src/line_and_column.hh @@ -27,15 +27,34 @@ struct LineAndColumn EffectiveType operator-(const EffectiveType& other) const { - return EffectiveType(line + other.line, column + other.column); + return EffectiveType(line - other.line, column - other.column); } EffectiveType& operator-=(const EffectiveType& other) { - line += other.line; - column += other.column; + line -= other.line; + column -= other.column; return *static_cast(this); } + + bool operator< (const EffectiveType& other) const + { + if (line != other.line) + return line < other.line; + return column < other.column; + } + + bool operator<= (const EffectiveType& other) const + { + if (line != other.line) + return line < other.line; + return column <= other.column; + } + + bool operator== (const EffectiveType& other) const + { + return line == other.line and column == other.column; + } }; }