From 13969024c97d90c89f23aeaaa8ad560bda8a977c Mon Sep 17 00:00:00 2001 From: Ben Clayton Date: Thu, 29 Jul 2021 19:55:35 +0000 Subject: [PATCH] symbol: Add operator<() Change-Id: I8e3eafd775a3aaa20cf8425e45f5bcae1e9e9851 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/60206 Commit-Queue: Ben Clayton Kokoro: Ben Clayton Kokoro: Kokoro Reviewed-by: Antonio Maiorano --- src/symbol.cc | 6 ++++++ src/symbol.h | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/src/symbol.cc b/src/symbol.cc index e77c699f52..9dc5726908 100644 --- a/src/symbol.cc +++ b/src/symbol.cc @@ -37,6 +37,12 @@ bool Symbol::operator==(const Symbol& other) const { return val_ == other.val_; } +bool Symbol::operator<(const Symbol& other) const { + TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(Symbol, program_id_, + other.program_id_); + return val_ < other.val_; +} + std::string Symbol::to_str() const { return "$" + std::to_string(val_); } diff --git a/src/symbol.h b/src/symbol.h index 286e20d51b..4567ca8568 100644 --- a/src/symbol.h +++ b/src/symbol.h @@ -54,6 +54,11 @@ class Symbol { /// @returns true if the symbols are the same bool operator==(const Symbol& o) const; + /// Less-than operator + /// @param o the other symbol + /// @returns true if this symbol is ordered before symbol `o` + bool operator<(const Symbol& o) const; + /// @returns true if the symbol is valid bool IsValid() const { return val_ != static_cast(-1); }