From 64a9a40fe867cc9f70f4710ed0419bd61887cc71 Mon Sep 17 00:00:00 2001 From: Sidney Congard Date: Mon, 18 Feb 2019 22:41:38 +0100 Subject: [PATCH] [Hashable] hana::integral_constant with an enum value implements Hashable --- include/boost/hana/hash.hpp | 10 ++++++++++ test/integral_constant/hash.cpp | 22 ++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/include/boost/hana/hash.hpp b/include/boost/hana/hash.hpp index 538ef36eca..0a42eca176 100644 --- a/include/boost/hana/hash.hpp +++ b/include/boost/hana/hash.hpp @@ -80,6 +80,16 @@ BOOST_HANA_NAMESPACE_BEGIN } }; + template + struct hash_integral_helper::value>::type + > { + template + static constexpr auto apply(X const&) { + return hana::type_c; + } + }; + template <> struct hash_integral_helper { template diff --git a/test/integral_constant/hash.cpp b/test/integral_constant/hash.cpp index 59cf070572..c628966d65 100644 --- a/test/integral_constant/hash.cpp +++ b/test/integral_constant/hash.cpp @@ -107,4 +107,26 @@ int main() { hana::type_c )); } + + // 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), + hana::type_c> + )); + + BOOST_HANA_CONSTANT_ASSERT(hana::equal( + hana::hash(hana::integral_c), + hana::type_c> + )); + + BOOST_HANA_CONSTANT_ASSERT(hana::equal( + hana::hash(hana::integral_c), + hana::type_c> + )); + } }