-
-
Notifications
You must be signed in to change notification settings - Fork 147
Heterogeneous lookup #80
Comments
It's more or less a bug, it's not yet implemented for |
Thanks for your answer, this also applies to the |
@NIKEA-SOFT
Reference: P0919R3 Heterogeneous lookup for unordered containers, Working Draft, Standard for Programming Language C++ — ISO C++ standards committee I believe that robin-hood-hashing defines these member functions correctly.
If you still think that robin-hood-hashing is not working properly, could you please let us know the detail of the problem and the environment in which you can reproduce the problem? Best regards. |
Hello, I also find it weird. Please check my example: template<size_t N>
using String = boost::beast::static_string<N>;
namespace std
{
template<size_t N>
struct hash<String<N>>
{
std::size_t operator()(const String<N> &str) const
{
return robin_hood::hash_bytes(str.data(), str.size());
}
std::size_t operator()(const char *str) const noexcept
{
return robin_hood::hash_bytes(str, std::strlen(str));
}
std::size_t operator()(string_view str) const noexcept
{
return robin_hood::hash_bytes(str.data(), str.size());
}
using is_transparent = void;
};
// Also tried this with std::equal_to<Key>
template <size_t N>
struct equal_to<String<N>>
{
// bool operator()(const char *lhs,
// const String<N> &rhs) const noexcept
// {
// return lhs == rhs;
// }
// bool operator()(const String<N> &lhs,
// const char *rhs) const noexcept
// {
// return lhs == rhs;
// }
bool operator()(const std::string_view &lhs,
const String<N> &rhs) const noexcept
{
return lhs == rhs;
}
// bool operator()(const String<N> &lhs,
// const std::string_view &rhs) const noexcept
// {
// return lhs == rhs;
// }
// template<size_t M>
// bool operator()(const String<N> &lhs,
// const String<M> &rhs) const noexcept
// {
// return lhs == rhs;
// }
template<size_t M>
bool operator()(const String<M> &lhs,
const String<N> &rhs) const noexcept
{
return lhs == rhs;
}
using is_transparent = void;
};
}
template <typename Key,
typename T,
typename Hash = robin_hood::hash<Key>,
typename KeyEqual = std::equal_to<>>
using UnorderedMap = robin_hood::unordered_flat_map<
Key, T, Hash, KeyEqual>;
TEST_CASE("UnorderedMap<String<N>,T>")
{
UnorderedMap<String<10>, int> map;
const auto &cmap = map;
REQUIRE(map.count("123") == 0);
REQUIRE(map.count("0") == 0);
REQUIRE(!map.contains("123"));
REQUIRE(!map.contains("0"));
REQUIRE(map.find("123") == map.end());
REQUIRE(map.find("0") == map.end());
REQUIRE(cmap.find("123") == map.cend());
REQUIRE(cmap.find("0") == map.cend());
REQUIRE(map.count(std::string_view{"123"}) == 0); // it fails here
// REQUIRE(map.count(std::string_view{"0"}) == 0);
// REQUIRE(!map.contains(std::string_view{"123"}));
// REQUIRE(!map.contains(std::string_view{"0"}));
// REQUIRE(map.find(std::string_view{"123"}) == map.end());
// REQUIRE(map.find(std::string_view{"0"}) == map.end());
// REQUIRE(cmap.find(std::string_view{"123"}) == map.cend());
// REQUIRE(cmap.find(std::string_view{"0"}) == map.cend());
map["123"];
REQUIRE(map.count("123") == 1);
REQUIRE(map.count("0") == 0);
REQUIRE(map.contains("123"));
REQUIRE(!map.contains("0"));
REQUIRE(map.find("123") == map.begin());
REQUIRE(map.find("0") == map.end());
REQUIRE(cmap.find("123") == map.cbegin());
REQUIRE(cmap.find("0") == map.cend());
// REQUIRE(map.count(std::string_view{"123"}) == 1);
// REQUIRE(map.count(std::string_view{"0"}) == 0);
// REQUIRE(map.contains(std::string_view{"123"}));
// REQUIRE(!map.contains(std::string_view{"0"}));
// REQUIRE(map.find(std::string_view{"123"}) == map.begin());
// REQUIRE(map.find(std::string_view{"0"}) == map.end());
// REQUIRE(cmap.find(std::string_view{"123"}) == map.cbegin());
// REQUIRE(cmap.find(std::string_view{"0"}) == map.cend());
} The output:
Any ideas? |
Clang 13.0.0 |
@ivan-volnov 1.
|
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.
The text was updated successfully, but these errors were encountered: