Skip to content

Commit f009d99

Browse files
committed
type_traits: further improve and cleanup is_equality_comparable
1 parent 206d2f6 commit f009d99

File tree

1 file changed

+16
-21
lines changed

1 file changed

+16
-21
lines changed

src/entt/core/type_traits.hpp

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -742,18 +742,6 @@ struct is_transparent<Type, std::void_t<typename Type::is_transparent>>: std::tr
742742
template<typename Type>
743743
inline constexpr bool is_transparent_v = is_transparent<Type>::value;
744744

745-
/**
746-
* @brief Provides the member constant `value` to true if a given type is
747-
* equality comparable, false otherwise.
748-
* @tparam Type The type to test.
749-
*/
750-
template<typename Type>
751-
struct is_equality_comparable;
752-
753-
/*! @copydoc is_equality_comparable */
754-
template<typename Type>
755-
struct is_equality_comparable<const Type>: is_equality_comparable<Type> {};
756-
757745
/**
758746
* @cond TURN_OFF_DOXYGEN
759747
* Internal details not to be documented.
@@ -775,7 +763,7 @@ struct has_value_type<Type, std::void_t<typename Type::value_type>>: std::true_t
775763

776764
template<typename Type, std::size_t... Index>
777765
[[nodiscard]] constexpr bool unpack_maybe_equality_comparable(std::index_sequence<Index...>) {
778-
return (is_equality_comparable<std::tuple_element_t<Index, Type>>::value && ...);
766+
return (dispatch_is_equality_comparable<std::tuple_element_t<Index, Type>>() && ...);
779767
}
780768

781769
template<typename>
@@ -789,13 +777,15 @@ template<typename Type>
789777
}
790778

791779
template<typename Type>
792-
[[nodiscard]] constexpr auto dispatch_is_equality_comparable() {
793-
if constexpr(has_tuple_size_value<Type>::value) {
780+
[[nodiscard]] constexpr bool dispatch_is_equality_comparable() {
781+
if constexpr(std::is_array_v<Type>) {
782+
return false;
783+
} else if constexpr(has_tuple_size_value<Type>::value) {
794784
return maybe_equality_comparable<Type>(0) && unpack_maybe_equality_comparable<Type>(std::make_index_sequence<std::tuple_size<Type>::value>{});
795785
} else if constexpr(has_value_type<Type>::value) {
796786
if constexpr(is_iterator_v<Type> || std::is_same_v<typename Type::value_type, Type>) {
797787
return maybe_equality_comparable<Type>(0);
798-
} else if constexpr(is_equality_comparable<typename Type::value_type>::value) {
788+
} else if constexpr(dispatch_is_equality_comparable<typename Type::value_type>()) {
799789
return maybe_equality_comparable<Type>(0);
800790
} else {
801791
return false;
@@ -807,17 +797,22 @@ template<typename Type>
807797

808798
} // namespace internal
809799

810-
template<typename Type>
811-
struct is_equality_comparable: std::bool_constant<internal::dispatch_is_equality_comparable<Type>()> {};
812-
813800
/**
814801
* Internal details not to be documented.
815802
* @endcond
816803
*/
817804

805+
/**
806+
* @brief Provides the member constant `value` to true if a given type is
807+
* equality comparable, false otherwise.
808+
* @tparam Type The type to test.
809+
*/
810+
template<typename Type>
811+
struct is_equality_comparable: std::bool_constant<internal::dispatch_is_equality_comparable<Type>()> {};
812+
818813
/*! @copydoc is_equality_comparable */
819-
template<typename Type, auto N>
820-
struct is_equality_comparable<Type[N]>: std::false_type {};
814+
template<typename Type>
815+
struct is_equality_comparable<const Type>: is_equality_comparable<Type> {};
821816

822817
/**
823818
* @brief Helper variable template.

0 commit comments

Comments
 (0)