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>
This commit is contained in:
Ben Clayton 2022-11-29 21:17:37 +00:00 committed by Dawn LUCI CQ
parent c158e845e6
commit 75b18674bf
3 changed files with 14 additions and 1 deletions

View File

@ -42,6 +42,11 @@ bool Symbol::operator==(const Symbol& other) const {
return val_ == other.val_; 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 { bool Symbol::operator<(const Symbol& other) const {
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(Symbol, program_id_, other.program_id_); TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(Symbol, program_id_, other.program_id_);
return val_ < other.val_; return val_ < other.val_;

View File

@ -63,11 +63,16 @@ class Symbol {
/// @returns teh symbol after doing the move /// @returns teh symbol after doing the move
Symbol& operator=(Symbol&& o); Symbol& operator=(Symbol&& o);
/// Comparison operator /// Equality operator
/// @param o the other symbol /// @param o the other symbol
/// @returns true if the symbols are the same /// @returns true if the symbols are the same
bool operator==(const Symbol& o) const; 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 /// Less-than operator
/// @param o the other symbol /// @param o the other symbol
/// @returns true if this symbol is ordered before symbol `o` /// @returns true if this symbol is ordered before symbol `o`

View File

@ -43,8 +43,11 @@ TEST_F(SymbolTest, Comparison) {
Symbol sym3(1, program_id); Symbol sym3(1, program_id);
EXPECT_TRUE(sym1 == sym3); EXPECT_TRUE(sym1 == sym3);
EXPECT_FALSE(sym1 != sym3);
EXPECT_FALSE(sym1 == sym2); EXPECT_FALSE(sym1 == sym2);
EXPECT_TRUE(sym1 != sym2);
EXPECT_FALSE(sym3 == sym2); EXPECT_FALSE(sym3 == sym2);
EXPECT_TRUE(sym3 != sym2);
} }
} // namespace } // namespace