Kaynağa Gözat

resource: less sfinae, more concepts

skypjack 1 ay önce
ebeveyn
işleme
c7828b380d
2 değiştirilmiş dosya ile 13 ekleme ve 10 silme
  1. 3 1
      src/entt/resource/cache.hpp
  2. 10 9
      src/entt/resource/resource.hpp

+ 3 - 1
src/entt/resource/cache.hpp

@@ -2,6 +2,7 @@
 #define ENTT_RESOURCE_RESOURCE_CACHE_HPP
 
 #include <compare>
+#include <concepts>
 #include <cstddef>
 #include <functional>
 #include <iterator>
@@ -41,7 +42,8 @@ public:
     constexpr resource_cache_iterator(const It iter) noexcept
         : it{iter} {}
 
-    template<typename Other, typename = std::enable_if_t<!std::is_same_v<It, Other> && std::is_constructible_v<It, Other>>>
+    template<typename Other>
+    requires !std::same_as<It, Other> && std::constructible_from<It, Other>
     constexpr resource_cache_iterator(const resource_cache_iterator<std::remove_const_t<Type>, Other> &other) noexcept
         : it{other.it} {}
 

+ 10 - 9
src/entt/resource/resource.hpp

@@ -2,8 +2,8 @@
 #define ENTT_RESOURCE_RESOURCE_HPP
 
 #include <compare>
+#include <concepts>
 #include <memory>
-#include <type_traits>
 #include <utility>
 #include "fwd.hpp"
 
@@ -24,9 +24,6 @@ class resource {
     template<typename>
     friend class resource;
 
-    template<typename Other>
-    static constexpr bool is_acceptable = !std::is_same_v<Type, Other> && std::is_constructible_v<Type &, Other &>;
-
 public:
     /*! @brief Resource type. */
     using element_type = Type;
@@ -65,7 +62,8 @@ public:
      * @tparam Other Type of resource managed by the received handle.
      * @param other The handle to copy from.
      */
-    template<typename Other, typename = std::enable_if_t<is_acceptable<Other>>>
+    template<typename Other>
+    requires !std::same_as<Type, Other> && std::constructible_from<Type &, Other &>
     resource(const resource<Other> &other) noexcept
         : value{other.value} {}
 
@@ -74,8 +72,9 @@ public:
      * @tparam Other Type of resource managed by the received handle.
      * @param other The handle to move from.
      */
-    template<typename Other, typename = std::enable_if_t<is_acceptable<Other>>>
-    resource(resource<Other> &&other) noexcept
+    template<typename Other>
+    requires !std::same_as<Type, Other> && std::constructible_from<Type &, Other &>
+    resource(resource<Other> && other) noexcept
         : value{std::move(other.value)} {}
 
     /*! @brief Default destructor. */
@@ -99,7 +98,8 @@ public:
      * @param other The handle to copy from.
      * @return This resource handle.
      */
-    template<typename Other, typename = std::enable_if_t<is_acceptable<Other>>>
+    template<typename Other>
+    requires (!std::same_as<Type, Other> && std::constructible_from<Type &, Other &>)
     resource &operator=(const resource<Other> &other) noexcept {
         value = other.value;
         return *this;
@@ -111,7 +111,8 @@ public:
      * @param other The handle to move from.
      * @return This resource handle.
      */
-    template<typename Other, typename = std::enable_if_t<is_acceptable<Other>>>
+    template<typename Other>
+    requires (!std::same_as<Type, Other> && std::constructible_from<Type &, Other &>)
     resource &operator=(resource<Other> &&other) noexcept {
         value = std::move(other.value);
         return *this;