From 772c2dba2fe5cd6508ee95fc99386f43ad5a2a8d Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Thu, 11 Feb 2021 11:57:55 +0100 Subject: [PATCH] type traits: add is_std_hashable[_v] (see #629) --- src/entt/core/type_traits.hpp | 32 ++++++++++++++++++++++++++++---- test/entt/core/type_traits.cpp | 5 +++++ 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/src/entt/core/type_traits.hpp b/src/entt/core/type_traits.hpp index ce51afe7b..f999e24e1 100644 --- a/src/entt/core/type_traits.hpp +++ b/src/entt/core/type_traits.hpp @@ -18,10 +18,10 @@ namespace entt { */ template struct choice_t - // Unfortunately, doxygen cannot parse such a construct. - /*! @cond TURN_OFF_DOXYGEN */ - : choice_t - /*! @endcond */ + // Unfortunately, doxygen cannot parse such a construct. + /*! @cond TURN_OFF_DOXYGEN */ + : choice_t + /*! @endcond */ {}; @@ -562,6 +562,30 @@ template inline constexpr auto is_complete_v = is_complete::value; +/** + * @brief Provides the member constant `value` to true if a given type is + * hashable, false otherwise. + * @tparam Type Potentially hashable type. + */ +template +struct is_std_hashable: std::false_type {}; + + +/*! @copydoc is_std_hashable */ +template +struct is_std_hashable>()(std::declval())), std::size_t>>> + : std::true_type +{}; + + +/** + * @brief Helper variable template. + * @tparam Type Potentially hashable type. + */ +template +inline constexpr auto is_std_hashable_v = is_std_hashable::value; + + /** * @brief Provides the member constant `value` to true if a given type is empty * and the empty type optimization is enabled, false otherwise. diff --git a/test/entt/core/type_traits.cpp b/test/entt/core/type_traits.cpp index b06bdf882..0bb4b7472 100644 --- a/test/entt/core/type_traits.cpp +++ b/test/entt/core/type_traits.cpp @@ -119,6 +119,11 @@ TEST(TypeTraits, IsComplete) { static_assert(!entt::is_complete_v); } +TEST(TypeTraits, IsStdHashable) { + static_assert(entt::is_std_hashable_v); + static_assert(!entt::is_std_hashable_v); +} + TEST(TypeTraits, ConstnessAs) { static_assert(std::is_same_v, int>); static_assert(std::is_same_v, int>);