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

[Hashable] hana::integral_constant with an enum value implements Hashable #440

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions include/boost/hana/hash.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@ BOOST_HANA_NAMESPACE_BEGIN
}
};

template <typename T>
struct hash_integral_helper<T,
typename std::enable_if<std::is_enum<T>::value>::type
> {
template <typename X>
static constexpr auto apply(X const&) {
return hana::type_c<X>;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just taking a second look at this, is there a reason it does not normalize to hana::type<hana::integral_constant<T, X::value> as the others do?

}
};

template <>
struct hash_integral_helper<bool> {
template <typename X>
Expand Down
22 changes: 22 additions & 0 deletions test/integral_constant/hash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,26 @@ int main() {
hana::type_c<hana::false_>
));
}

// Enumeration constants should hash to themselves
{
enum enum_1 { zero };
enum class enum_2 { zero };
enum class enum_3 : unsigned { zero };

BOOST_HANA_CONSTANT_ASSERT(hana::equal(
hana::hash(hana::integral_c<enum_1, zero>),
hana::type_c<hana::integral_constant<enum_1, zero>>
));

BOOST_HANA_CONSTANT_ASSERT(hana::equal(
hana::hash(hana::integral_c<enum_2, enum_2::zero>),
hana::type_c<hana::integral_constant<enum_2, enum_2::zero>>
));

BOOST_HANA_CONSTANT_ASSERT(hana::equal(
hana::hash(hana::integral_c<enum_3, enum_3::zero>),
hana::type_c<hana::integral_constant<enum_3, enum_3::zero>>
));
}
}