tint: Add Symbol inequality operator
Allows Symbol to be used in a std::variant
Change-Id: If366622c39b5c25d633f6507467c9859394577c3
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/112283
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Kokoro: Ben Clayton <bclayton@google.com>
diff --git a/src/tint/symbol.cc b/src/tint/symbol.cc
index 9adc1aa..32177f6 100644
--- a/src/tint/symbol.cc
+++ b/src/tint/symbol.cc
@@ -42,6 +42,11 @@
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_;
+}
+
bool Symbol::operator<(const Symbol& other) const {
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(Symbol, program_id_, other.program_id_);
return val_ < other.val_;
diff --git a/src/tint/symbol.h b/src/tint/symbol.h
index fc0a0df..c093673 100644
--- a/src/tint/symbol.h
+++ b/src/tint/symbol.h
@@ -63,11 +63,16 @@
/// @returns teh symbol after doing the move
Symbol& operator=(Symbol&& o);
- /// Comparison operator
+ /// Equality operator
/// @param o the other symbol
/// @returns true if the symbols are the same
bool operator==(const Symbol& o) const;
+ /// Inequality operator
+ /// @param o the other symbol
+ /// @returns true if the symbols are the different
+ bool operator!=(const Symbol& o) const;
+
/// Less-than operator
/// @param o the other symbol
/// @returns true if this symbol is ordered before symbol `o`
diff --git a/src/tint/symbol_test.cc b/src/tint/symbol_test.cc
index 22135b5..db8e321 100644
--- a/src/tint/symbol_test.cc
+++ b/src/tint/symbol_test.cc
@@ -43,8 +43,11 @@
Symbol sym3(1, program_id);
EXPECT_TRUE(sym1 == sym3);
+ EXPECT_FALSE(sym1 != sym3);
EXPECT_FALSE(sym1 == sym2);
+ EXPECT_TRUE(sym1 != sym2);
EXPECT_FALSE(sym3 == sym2);
+ EXPECT_TRUE(sym3 != sym2);
}
} // namespace