Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow Hasher as a type parameter to hash_map #5

Open
kkostrzewa opened this issue Oct 26, 2020 · 0 comments
Open

allow Hasher as a type parameter to hash_map #5

kkostrzewa opened this issue Oct 26, 2020 · 0 comments

Comments

@kkostrzewa
Copy link

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 },
});
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant