mirror of
https://github.com/facebook/sapling.git
synced 2024-10-07 15:27:13 +03:00
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:
parent
f6ce5af065
commit
cdbded6c87
@ -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);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user