فهرست منبع

type_traits: more concepts, less sfinae

skypjack 1 ماه پیش
والد
کامیت
7d2321efde
1فایلهای تغییر یافته به همراه16 افزوده شده و 13 حذف شده
  1. 16 13
      src/entt/core/type_traits.hpp

+ 16 - 13
src/entt/core/type_traits.hpp

@@ -1,6 +1,7 @@
 #ifndef ENTT_CORE_TYPE_TRAITS_HPP
 #ifndef ENTT_CORE_TYPE_TRAITS_HPP
 #define ENTT_CORE_TYPE_TRAITS_HPP
 #define ENTT_CORE_TYPE_TRAITS_HPP
 
 
+#include <concepts>
 #include <cstddef>
 #include <cstddef>
 #include <iterator>
 #include <iterator>
 #include <tuple>
 #include <tuple>
@@ -36,12 +37,13 @@ inline constexpr choice_t<N> choice{};
  * @brief A type-only `sizeof` wrapper that returns 0 where `sizeof` complains.
  * @brief A type-only `sizeof` wrapper that returns 0 where `sizeof` complains.
  * @tparam Type The type of which to return the size.
  * @tparam Type The type of which to return the size.
  */
  */
-template<typename Type, typename = void>
+template<typename Type>
 struct size_of: std::integral_constant<std::size_t, 0u> {};
 struct size_of: std::integral_constant<std::size_t, 0u> {};
 
 
 /*! @copydoc size_of */
 /*! @copydoc size_of */
 template<typename Type>
 template<typename Type>
-struct size_of<Type, std::void_t<decltype(sizeof(Type))>>
+requires requires { sizeof(Type); }
+struct size_of<Type>
     // NOLINTNEXTLINE(bugprone-sizeof-expression)
     // NOLINTNEXTLINE(bugprone-sizeof-expression)
     : std::integral_constant<std::size_t, sizeof(Type)> {};
     : std::integral_constant<std::size_t, sizeof(Type)> {};
 
 
@@ -634,12 +636,13 @@ inline constexpr bool is_applicable_r_v = is_applicable_r<Ret, Func, Args>::valu
  * complete, false otherwise.
  * complete, false otherwise.
  * @tparam Type The type to test.
  * @tparam Type The type to test.
  */
  */
-template<typename Type, typename = void>
+template<typename Type>
 struct is_complete: std::false_type {};
 struct is_complete: std::false_type {};
 
 
 /*! @copydoc is_complete */
 /*! @copydoc is_complete */
 template<typename Type>
 template<typename Type>
-struct is_complete<Type, std::void_t<decltype(sizeof(Type))>>: std::true_type {};
+requires requires { sizeof(Type); }
+struct is_complete<Type>: std::true_type {};
 
 
 /**
 /**
  * @brief Helper variable template.
  * @brief Helper variable template.
@@ -653,17 +656,18 @@ inline constexpr bool is_complete_v = is_complete<Type>::value;
  * iterator, false otherwise.
  * iterator, false otherwise.
  * @tparam Type The type to test.
  * @tparam Type The type to test.
  */
  */
-template<typename Type, typename = void>
+template<typename Type>
 struct is_iterator: std::false_type {};
 struct is_iterator: std::false_type {};
 
 
 /*! @cond ENTT_INTERNAL */
 /*! @cond ENTT_INTERNAL */
 namespace internal {
 namespace internal {
 
 
-template<typename, typename = void>
+template<typename>
 struct has_iterator_category: std::false_type {};
 struct has_iterator_category: std::false_type {};
 
 
 template<typename Type>
 template<typename Type>
-struct has_iterator_category<Type, std::void_t<typename std::iterator_traits<Type>::iterator_category>>: std::true_type {};
+requires requires { typename std::iterator_traits<Type>::iterator_category; }
+struct has_iterator_category<Type>: std::true_type {};
 
 
 } // namespace internal
 } // namespace internal
 /*! @endcond */
 /*! @endcond */
@@ -671,8 +675,7 @@ struct has_iterator_category<Type, std::void_t<typename std::iterator_traits<Typ
 /*! @copydoc is_iterator */
 /*! @copydoc is_iterator */
 template<typename Type>
 template<typename Type>
 requires (!std::is_void_v<std::remove_const_t<std::remove_pointer_t<Type>>>)
 requires (!std::is_void_v<std::remove_const_t<std::remove_pointer_t<Type>>>)
-struct is_iterator<Type>
-    : internal::has_iterator_category<Type> {};
+struct is_iterator<Type>: internal::has_iterator_category<Type> {};
 
 
 /**
 /**
  * @brief Helper variable template.
  * @brief Helper variable template.
@@ -687,8 +690,7 @@ inline constexpr bool is_iterator_v = is_iterator<Type>::value;
  * @tparam Type The type to test
  * @tparam Type The type to test
  */
  */
 template<typename Type>
 template<typename Type>
-struct is_ebco_eligible
-    : std::bool_constant<std::is_empty_v<Type> && !std::is_final_v<Type>> {};
+struct is_ebco_eligible: std::bool_constant<std::is_empty_v<Type> && !std::is_final_v<Type>> {};
 
 
 /**
 /**
  * @brief Helper variable template.
  * @brief Helper variable template.
@@ -720,11 +722,12 @@ inline constexpr bool is_transparent_v = is_transparent<Type>::value;
 /*! @cond ENTT_INTERNAL */
 /*! @cond ENTT_INTERNAL */
 namespace internal {
 namespace internal {
 
 
-template<typename, typename = void>
+template<typename>
 struct has_tuple_size_value: std::false_type {};
 struct has_tuple_size_value: std::false_type {};
 
 
 template<typename Type>
 template<typename Type>
-struct has_tuple_size_value<Type, std::void_t<decltype(std::tuple_size<const Type>::value)>>: std::true_type {};
+requires is_complete_v<std::tuple_size<const Type>>
+struct has_tuple_size_value<Type>: std::true_type {};
 
 
 template<typename>
 template<typename>
 struct has_value_type: std::false_type {};
 struct has_value_type: std::false_type {};