Make util::hash_table more heterogeneous-friendly

This commit is contained in:
Nikita Lisitsa 2024-06-03 14:35:58 +03:00
parent bd1393c505
commit cbd99d1c4d

View file

@ -373,17 +373,14 @@ namespace psemek::util
: Hash(hash)
{}
std::size_t operator()(Key const & key) const
template <typename Key1>
std::size_t operator()(Key1 const & key) const
{
return static_cast<Hash const &>(*this)(key);
}
std::size_t operator()(std::pair<Key const, Value> const & pair) const
{
return static_cast<Hash const &>(*this)(pair.first);
}
std::size_t operator()(std::pair<Key, Value> const & pair) const
template <typename Key1, typename Value1>
std::size_t operator()(std::pair<Key1, Value1> const & pair) const
{
return static_cast<Hash const &>(*this)(pair.first);
}
@ -397,22 +394,20 @@ namespace psemek::util
: Equal(equal)
{}
bool operator()(Key const & key1, std::pair<Key const, Value> const & pair2) const
template <typename Key1, typename Key2, typename Value2>
bool operator()(Key1 const & key1, std::pair<Key2, Value2> const & pair2) const
{
return static_cast<Equal const &>(*this)(key1, pair2.first);
}
bool operator()(std::pair<Key const, Value> const & pair1, Key const & key2) const
template <typename Key1, typename Value1, typename Key2>
bool operator()(std::pair<Key1, Value1> const & pair1, Key2 const & key2) const
{
return static_cast<Equal const &>(*this)(pair1.first, key2);
}
bool operator()(std::pair<Key const, Value> const & pair1, std::pair<Key const, Value> const & pair2) const
{
return static_cast<Equal const &>(*this)(pair1.first, pair2.first);
}
bool operator()(std::pair<Key, Value> const & pair1, std::pair<Key const, Value> const & pair2) const
template <typename Key1, typename Value1, typename Key2, typename Value2>
bool operator()(std::pair<Key1, Value1> const & pair1, std::pair<Key2, Value2> const & pair2) const
{
return static_cast<Equal const &>(*this)(pair1.first, pair2.first);
}
@ -644,7 +639,7 @@ namespace psemek::util
{
auto it = find(key);
if (it == end())
throw util::key_error{key};
throw util::key_error<Key>(key);
return it->second;
}
@ -653,7 +648,7 @@ namespace psemek::util
{
auto it = find(key);
if (it == end())
throw util::key_error{key};
throw util::key_error<Key>(key);
return it->second;
}
@ -661,7 +656,7 @@ namespace psemek::util
{
auto it = find(key);
if (it == end())
throw util::key_error{key};
throw util::key_error<Key>(key);
return it->second;
}
@ -670,7 +665,7 @@ namespace psemek::util
{
auto it = find(key);
if (it == end())
throw util::key_error{key};
throw util::key_error<Key>(key);
return it->second;
}