Skip to content

Commit 6187f70

Browse files
ezbrcopybara-github
authored andcommitted
Add a test case that type-erased absl::HashState is consistent with absl::HashOf.
PiperOrigin-RevId: 711802644 Change-Id: I8a858340f9eefcd72ca82e7b11e27aba7a3d6202
1 parent d910383 commit 6187f70

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

absl/hash/hash_test.cc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,4 +1195,22 @@ TEST(HashOf, CantPassExplicitTemplateParameters) {
11951195
EXPECT_FALSE(HashOfExplicitParameter<int>(0));
11961196
}
11971197

1198+
struct TypeErasedHashStateUser {
1199+
int a;
1200+
std::string b;
1201+
1202+
template <typename H>
1203+
friend H AbslHashValue(H state, const TypeErasedHashStateUser& value) {
1204+
absl::HashState type_erased_state = absl::HashState::Create(&state);
1205+
absl::HashState::combine(std::move(type_erased_state), value.a, value.b);
1206+
return state;
1207+
}
1208+
};
1209+
1210+
TEST(HashOf, MatchesTypeErasedHashState) {
1211+
std::string s = "s";
1212+
EXPECT_EQ(absl::HashOf(1, s), absl::Hash<TypeErasedHashStateUser>{}(
1213+
TypeErasedHashStateUser{1, s}));
1214+
}
1215+
11981216
} // namespace

0 commit comments

Comments
 (0)