This repository was archived by the owner on Dec 26, 2023. It is now read-only.
This repository was archived by the owner on Dec 26, 2023. It is now read-only.
Heterogeneous lookup #80
Open
Description
Hello, first of all I would like to thank you for your library.
I noticed that you added a “Heterogeneous lookup” in the latest updates, however, I still couldn’t get it working.
struct string_hash
{
using is_transparent = void;
std::size_t operator()(const std::string& key) const { return robin_hood::hash_bytes(key.c_str(), key.size()); }
std::size_t operator()(std::string_view key) const { return robin_hood::hash_bytes(key.data(), key.size()); }
std::size_t operator()(const char* key) const { return robin_hood::hash_bytes(key, std::strlen(key)); }
};
struct string_equal
{
using is_transparent = int;
bool operator()(std::string_view lhs, const std::string& rhs) const {
const std::string_view view = rhs;
return lhs == view;
}
bool operator()(const char* lhs, const std::string& rhs) const {
return std::strcmp(lhs, rhs.c_str()) == 0;
}
bool operator()(const std::string& lhs, const std::string& rhs) const {
return lhs == rhs;
}
};
int main()
{
robin_hood::unordered_flat_map<std::string, uint64_t, string_hash, string_equal> map;
std::string_view key = "key";
map.emplace(key, 100);
const auto it = map.find(key); // fail
}