eden: enable std::hash for path types

Summary:
I have a follow on diff that needs this to work; this just injects the
existing hash functions that we're using for the boost hash stuff into
`std::hash` and checks that `set` and `unordered_set` compile.

Reviewed By: simpkins

Differential Revision: D3659318

fbshipit-source-id: 57920dbcd5f6e5449fd67769e379f8b3846a47f3
This commit is contained in:
Wez Furlong 2016-08-02 17:43:51 -07:00 committed by Facebook Github Bot 5
parent f6ce5af065
commit cdbded6c87
2 changed files with 37 additions and 0 deletions

View File

@ -996,3 +996,31 @@ RelativePath operator+(
}
}
namespace std {
/* Allow std::hash to operate on these types */
template <typename A>
struct hash<facebook::eden::detail::PathComponentBase<A>> {
std::size_t operator()(
const facebook::eden::detail::PathComponentBase<A>& s) const {
return facebook::eden::detail::hash_value(s);
}
};
template <typename A>
struct hash<facebook::eden::detail::RelativePathBase<A>> {
std::size_t operator()(
const facebook::eden::detail::RelativePathBase<A>& s) const {
return facebook::eden::detail::hash_value(s);
}
};
template <typename A>
struct hash<facebook::eden::detail::AbsolutePathBase<A>> {
std::size_t operator()(
const facebook::eden::detail::AbsolutePathBase<A>& s) const {
return facebook::eden::detail::hash_value(s);
}
};
}

View File

@ -174,6 +174,15 @@ TEST(PathFuncs, Hash) {
// namespace for boost::hash.
boost::hash<PathComponentPiece> hasher;
EXPECT_EQ(9188533406165618471, hasher(PathComponentPiece("foo")));
// Similarly for std::hash
std::set<PathComponent> pset;
std::set<RelativePath> rset;
std::set<AbsolutePath> aset;
std::unordered_set<PathComponent> upset;
std::unordered_set<RelativePath> urset;
std::unordered_set<AbsolutePath> uaset;
}
TEST(PathFuncs, Stream) {