Skip to content

Commit 64a9a40

Browse files
committed
[Hashable] hana::integral_constant with an enum value implements Hashable
1 parent 4536973 commit 64a9a40

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

Diff for: include/boost/hana/hash.hpp

+10
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,16 @@ BOOST_HANA_NAMESPACE_BEGIN
8080
}
8181
};
8282

83+
template <typename T>
84+
struct hash_integral_helper<T,
85+
typename std::enable_if<std::is_enum<T>::value>::type
86+
> {
87+
template <typename X>
88+
static constexpr auto apply(X const&) {
89+
return hana::type_c<X>;
90+
}
91+
};
92+
8393
template <>
8494
struct hash_integral_helper<bool> {
8595
template <typename X>

Diff for: test/integral_constant/hash.cpp

+22
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,26 @@ int main() {
107107
hana::type_c<hana::false_>
108108
));
109109
}
110+
111+
// Enumeration constants should hash to themselves
112+
{
113+
enum enum_1 { zero };
114+
enum class enum_2 { zero };
115+
enum class enum_3 : unsigned { zero };
116+
117+
BOOST_HANA_CONSTANT_ASSERT(hana::equal(
118+
hana::hash(hana::integral_c<enum_1, zero>),
119+
hana::type_c<hana::integral_constant<enum_1, zero>>
120+
));
121+
122+
BOOST_HANA_CONSTANT_ASSERT(hana::equal(
123+
hana::hash(hana::integral_c<enum_2, enum_2::zero>),
124+
hana::type_c<hana::integral_constant<enum_2, enum_2::zero>>
125+
));
126+
127+
BOOST_HANA_CONSTANT_ASSERT(hana::equal(
128+
hana::hash(hana::integral_c<enum_3, enum_3::zero>),
129+
hana::type_c<hana::integral_constant<enum_3, enum_3::zero>>
130+
));
131+
}
110132
}

0 commit comments

Comments
 (0)