mapbox/eternal

allow Hasher as a type parameter to hash_map

kkostrzewa opened this issue · 0 comments

Thanks for this library - this is great stuff - very useful to me!

I'm using hash_map where I want the key of the hash to be an int, and that's colliding with a predefined non-constexpr std::hash type, causing a compile time error

constexpr auto TemplateFieldRecs_forms_hash = mapbox::eternal::hash_map<int, v<TemplateFieldRecs_>>({ {1, TemplateFieldRecs_form1_array }, {2, TemplateFieldRecs_form2_array }, });

I was able to workaround this with a hash_map overload like this, where I could pass Hasher as a template parameter

`
namespace mapbox {
namespace eternal {
template <typename Key, typename Value, typename Hasher, std::size_t N>
static constexpr auto hash_map(const std::pair<const Key, const Value>(&items)[N]) noexcept {
return impl::map<impl::element_hash<Key, Value, Hasher>, N>(items);
}
}
}

constexpr auto TemplateFieldRecs_forms_hash = mapbox::eternal::hash_map<int, v<TemplateFieldRecs_>, ConstexprIntHasher>({
{1, TemplateFieldRecs_form1_array },
{2, TemplateFieldRecs_form2_array },
});
`