Commit 78890b3f authored by Tavian Barnes's avatar Tavian Barnes Committed by Facebook Github Bot 1

fbstring: Fix std::hash specializations for non-char types

Summary: Closes https://github.com/facebook/folly/pull/407

Reviewed By: ot

Differential Revision: D3428571

Pulled By: Orvid

fbshipit-source-id: 0b82afae2df24803250e8d6005e2e59bbc8348c9
parent 9be1d48f
...@@ -2441,7 +2441,7 @@ _GLIBCXX_END_NAMESPACE_VERSION ...@@ -2441,7 +2441,7 @@ _GLIBCXX_END_NAMESPACE_VERSION
#define FOLLY_FBSTRING_HASH1(T) \ #define FOLLY_FBSTRING_HASH1(T) \
template <> \ template <> \
struct hash< ::folly::basic_fbstring<T> > { \ struct hash< ::folly::basic_fbstring<T> > { \
size_t operator()(const ::folly::fbstring& s) const { \ size_t operator()(const ::folly::basic_fbstring<T>& s) const { \
return ::folly::hash::fnv32_buf(s.data(), s.size()); \ return ::folly::hash::fnv32_buf(s.data(), s.size()); \
} \ } \
}; };
......
...@@ -1287,6 +1287,18 @@ TEST(FBString, testHash) { ...@@ -1287,6 +1287,18 @@ TEST(FBString, testHash) {
EXPECT_NE(hashfunc(a), hashfunc(b)); EXPECT_NE(hashfunc(a), hashfunc(b));
} }
TEST(FBString, testHashChar16) {
using u16fbstring = basic_fbstring<char16_t>;
u16fbstring a;
u16fbstring b;
a.push_back(0);
a.push_back(1);
b.push_back(0);
b.push_back(2);
std::hash<u16fbstring> hashfunc;
EXPECT_NE(hashfunc(a), hashfunc(b));
}
TEST(FBString, testFrontBack) { TEST(FBString, testFrontBack) {
fbstring str("hello"); fbstring str("hello");
EXPECT_EQ(str.front(), 'h'); EXPECT_EQ(str.front(), 'h');
......
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