martinus / unordered_dense

A fast & densely stored hashmap and hashset based on robin-hood backward shift deletion
MIT License
898 stars 72 forks source link

Support heterogeneous C++26 overloads #35

Closed iwubcode closed 2 years ago

iwubcode commented 2 years ago

Would you be interested in updating unordered_dense to support heterogeneous overloads outlined in the paper: https://github.com/cplusplus/papers/issues/1037 (which seems like it is a go for C++26)

It can be helpful when trying to do a find on an object that the map doesn't directly support but can be looked up...but still requiring an insert of the real type if it doesn't exist.


Contrived example

Today:

ankerl::unordered_dense::map<std::string, int, StringHash, std::equal_to<>> map;
auto it = map.find(std::string_view{"hello world"});
if (it == map.end())
{
  auto [ new_it, success ] = map.emplace(std::string{"hello world"}, 42);
  it = new_it
}
// do something with it

Future:

ankerl::unordered_dense::map<std::string, int, StringHash, std::equal_to<>> map;
auto [ it, success ] = map.try_emplace(std::string_view{"hello world"}, 42);
// do something with it
martinus commented 2 years ago

Hi, certainly sounds like a good idea. Direct link to the API summary of P2364R3: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2363r3.html#summary

martinus commented 2 years ago

Implemented in #36, will create release v1.4.0

iwubcode commented 2 years ago

Thank you so much @martinus !! Really loving your project. Appreciate all the hard work.