Commit c1527c03 authored by Sean Purcell's avatar Sean Purcell Committed by Facebook Github Bot

Add folly::hasher for empty tuples

Summary:
This ensures that we can use any tuple type in maps/other places where
hashes are useful.  Since there's only one value for an empty tuple, just
return 0.

Reviewed By: ot

Differential Revision: D14898947

fbshipit-source-id: 8fefab46df32a6cc56e43b02346bbefe4d4ec567
parent 0d0b02a4
......@@ -367,6 +367,10 @@ struct Hash {
size_t operator()(const T& t, const Ts&... ts) const {
return hash::hash_128_to_64((*this)(t), (*this)(ts...));
}
size_t operator()() const noexcept {
return 0;
}
};
// IsAvalanchingHasher<H, K> extends std::integral_constant<bool, V>.
......
......@@ -495,6 +495,15 @@ TEST(Hash, std_tuple) {
EXPECT_EQ("bar", m[t]);
}
TEST(Hash, std_empty_tuple) {
std::unordered_map<std::tuple<>, std::string, folly::Hash> m;
m[{}] = "foo";
EXPECT_EQ(m[{}], "foo");
folly::hasher<std::tuple<>> h;
EXPECT_EQ(h({}), 0);
}
TEST(Hash, enum_type) {
const auto hash = folly::Hash();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment