Kaynağa Gözat

entt: use cvref_unqualified as needed

skypjack 1 ay önce
ebeveyn
işleme
e09593b44b

+ 3 - 5
src/entt/core/any.hpp

@@ -6,6 +6,7 @@
 #include <type_traits>
 #include <utility>
 #include "../config/config.h"
+#include "../core/concepts.hpp"
 #include "fwd.hpp"
 #include "type_info.hpp"
 #include "type_traits.hpp"
@@ -66,10 +67,8 @@ class basic_any: private internal::basic_any_storage<Len, Align> {
     template<typename Type>
     static constexpr bool in_situ_v = internal::in_situ<Type, Len, Align>::value;
 
-    template<typename Type>
+    template<cvref_unqualified Type>
     static const void *basic_vtable(const request req, const basic_any &value, const void *other) {
-        static_assert(std::is_same_v<std::remove_cvref_t<Type>, Type>, "Invalid type");
-
         switch(const auto *elem = static_cast<const Type *>(value.data()); req) {
             using enum internal::any_request;
         case info:
@@ -110,9 +109,8 @@ class basic_any: private internal::basic_any_storage<Len, Align> {
         return nullptr;
     }
 
-    template<typename Type>
+    template<cvref_unqualified Type>
     static void basic_deleter(const basic_any &value) {
-        static_assert(std::is_same_v<std::remove_cvref_t<Type>, Type>, "Invalid type");
         ENTT_ASSERT((value.mode == any_policy::dynamic) || ((value.mode == any_policy::embedded) && !std::is_trivially_destructible_v<Type>), "Unexpected policy");
 
         const auto *elem = static_cast<const Type *>(value.data());

+ 2 - 3
src/entt/entity/component.hpp

@@ -5,6 +5,7 @@
 #include <cstddef>
 #include <type_traits>
 #include "../config/config.h"
+#include "../core/concepts.hpp"
 #include "fwd.hpp"
 
 namespace entt {
@@ -40,10 +41,8 @@ struct page_size<Type>: std::integral_constant<std::size_t, Type::page_size> {};
  * @tparam Type Element type.
  * @tparam Entity A valid entity type.
  */
-template<typename Type, entity_like Entity, typename>
+template<cvref_unqualified Type, entity_like Entity, typename>
 struct component_traits {
-    static_assert(std::is_same_v<std::decay_t<Type>, Type>, "Unsupported type");
-
     /*! @brief Element type. */
     using element_type = Type;
     /*! @brief Underlying entity identifier. */

+ 2 - 1
src/entt/entity/fwd.hpp

@@ -5,6 +5,7 @@
 #include <memory>
 #include <type_traits>
 #include "../config/config.h"
+#include "../core/concepts.hpp"
 #include "../core/fwd.hpp"
 #include "../core/type_traits.hpp"
 
@@ -43,7 +44,7 @@ enum class deletion_policy : std::uint8_t {
     unspecified = swap_and_pop
 };
 
-template<typename Type, entity_like Entity = entity, typename = void>
+template<cvref_unqualified Type, entity_like Entity = entity, typename = void>
 struct component_traits;
 
 template<entity_like Entity = entity, typename = std::allocator<Entity>>

+ 3 - 6
src/entt/entity/registry.hpp

@@ -17,6 +17,7 @@
 #include "../container/dense_map.hpp"
 #include "../core/algorithm.hpp"
 #include "../core/any.hpp"
+#include "../core/concepts.hpp"
 #include "../core/fwd.hpp"
 #include "../core/iterator.hpp"
 #include "../core/memory.hpp"
@@ -218,10 +219,8 @@ class basic_registry {
     using group_container_type = dense_map<id_type, std::shared_ptr<internal::group_descriptor>, stl::identity, std::equal_to<>, typename alloc_traits::template rebind_alloc<std::pair<const id_type, std::shared_ptr<internal::group_descriptor>>>>;
     using traits_type = entt_traits<Entity>;
 
-    template<typename Type>
+    template<cvref_unqualified Type>
     [[nodiscard]] auto &assure([[maybe_unused]] const id_type id = type_hash<Type>::value()) {
-        static_assert(std::is_same_v<Type, std::decay_t<Type>>, "Non-decayed types not allowed");
-
         if constexpr(std::is_same_v<Type, entity_type>) {
             ENTT_ASSERT(id == type_hash<Type>::value(), "User entity storage not allowed");
             return entities;
@@ -241,10 +240,8 @@ class basic_registry {
         }
     }
 
-    template<typename Type>
+    template<cvref_unqualified Type>
     [[nodiscard]] const auto *assure([[maybe_unused]] const id_type id = type_hash<Type>::value()) const {
-        static_assert(std::is_same_v<Type, std::decay_t<Type>>, "Non-decayed types not allowed");
-
         if constexpr(std::is_same_v<Type, entity_type>) {
             ENTT_ASSERT(id == type_hash<Type>::value(), "User entity storage not allowed");
             return &entities;

+ 4 - 8
src/entt/entity/view.hpp

@@ -9,6 +9,7 @@
 #include <type_traits>
 #include <utility>
 #include "../config/config.h"
+#include "../core/concepts.hpp"
 #include "../core/iterator.hpp"
 #include "../core/type_traits.hpp"
 #include "entity.hpp"
@@ -23,9 +24,8 @@ template<typename... Type>
 // NOLINTNEXTLINE(misc-redundant-expression)
 static constexpr bool tombstone_check_v = ((sizeof...(Type) == 1u) && ... && (Type::storage_policy == deletion_policy::in_place));
 
-template<typename Type>
+template<cvref_unqualified Type>
 const Type *view_placeholder() {
-    static_assert(std::is_same_v<std::remove_cvref_t<Type>, Type>, "Unexpected type");
     static const Type placeholder{};
     return &placeholder;
 }
@@ -210,10 +210,8 @@ class basic_view;
  * @tparam Get Number of storage iterated by the view.
  * @tparam Exclude Number of storage used to filter the view.
  */
-template<typename Type, bool Checked, std::size_t Get, std::size_t Exclude>
+template<cvref_unqualified Type, bool Checked, std::size_t Get, std::size_t Exclude>
 class basic_common_view {
-    static_assert(std::is_same_v<std::remove_cvref_t<Type>, Type>, "Unexpected type");
-
     template<typename Return, typename View, typename Other, std::size_t... GLhs, std::size_t... ELhs, std::size_t... GRhs, std::size_t... ERhs>
     friend Return internal::view_pack(const View &, const Other &, std::index_sequence<GLhs...>, std::index_sequence<ELhs...>, std::index_sequence<GRhs...>, std::index_sequence<ERhs...>);
 
@@ -674,10 +672,8 @@ public:
  * @tparam Type Common type among all storage types.
  * @tparam Policy Storage policy.
  */
-template<typename Type, deletion_policy Policy>
+template<cvref_unqualified Type, deletion_policy Policy>
 class basic_storage_view {
-    static_assert(std::is_same_v<std::remove_cvref_t<Type>, Type>, "Unexpected type");
-
 protected:
     /*! @cond ENTT_INTERNAL */
     basic_storage_view() noexcept = default;

+ 3 - 6
src/entt/meta/container.hpp

@@ -16,6 +16,7 @@
 #include <vector>
 #include "../container/dense_map.hpp"
 #include "../container/dense_set.hpp"
+#include "../core/concepts.hpp"
 #include "../core/type_traits.hpp"
 #include "context.hpp"
 #include "fwd.hpp"
@@ -61,10 +62,8 @@ inline constexpr bool reserve_aware_container_v = reserve_aware_container<Type>:
  * @brief General purpose implementation of meta sequence container traits.
  * @tparam Type Type of underlying sequence container.
  */
-template<typename Type>
+template<cvref_unqualified Type>
 struct basic_meta_sequence_container_traits {
-    static_assert(std::is_same_v<Type, std::remove_cvref_t<Type>>, "Unexpected type");
-
     /*! @brief Unsigned integer type. */
     using size_type = meta_sequence_container::size_type;
     /*! @brief Meta iterator type. */
@@ -185,10 +184,8 @@ struct basic_meta_sequence_container_traits {
  * @brief General purpose implementation of meta associative container traits.
  * @tparam Type Type of underlying associative container.
  */
-template<typename Type>
+template<cvref_unqualified Type>
 struct basic_meta_associative_container_traits {
-    static_assert(std::is_same_v<Type, std::remove_cvref_t<Type>>, "Unexpected type");
-
     /*! @brief Unsigned integer type. */
     using size_type = meta_associative_container::size_type;
     /*! @brief Meta iterator type. */

+ 2 - 3
src/entt/meta/meta.hpp

@@ -11,6 +11,7 @@
 #include <utility>
 #include "../config/config.h"
 #include "../core/any.hpp"
+#include "../core/concepts.hpp"
 #include "../core/fwd.hpp"
 #include "../core/iterator.hpp"
 #include "../core/type_info.hpp"
@@ -176,10 +177,8 @@ private:
 class meta_any {
     using vtable_type = void(const internal::meta_traits, const meta_any &, const void *);
 
-    template<typename Type>
+    template<cvref_unqualified Type>
     static void basic_vtable(const internal::meta_traits req, const meta_any &value, [[maybe_unused]] const void *other) {
-        static_assert(std::is_same_v<std::remove_cvref_t<Type>, Type>, "Invalid type");
-
         if(req == internal::meta_traits::is_none) {
             value.node = &internal::resolve<Type>(internal::meta_context::from(*value.ctx));
         }

+ 3 - 3
src/entt/meta/node.hpp

@@ -10,6 +10,7 @@
 #include <vector>
 #include "../config/config.h"
 #include "../core/bit.hpp"
+#include "../core/concepts.hpp"
 #include "../core/enum.hpp"
 #include "../core/fwd.hpp"
 #include "../core/type_info.hpp"
@@ -183,7 +184,7 @@ template<auto Member>
     return static_cast<value_type *>(nullptr);
 }
 
-template<typename Type>
+template<cvref_unqualified Type>
 const meta_type_node &resolve(const meta_context &) noexcept;
 
 template<typename... Args>
@@ -273,9 +274,8 @@ auto setup_node_for() noexcept {
     return (it != context.bucket.end()) ? it->second.get() : nullptr;
 }
 
-template<typename Type>
+template<cvref_unqualified Type>
 [[nodiscard]] const meta_type_node &resolve(const meta_context &context) noexcept {
-    static_assert(std::is_same_v<Type, std::remove_cvref_t<Type>>, "Invalid type");
     static const meta_type_node node = setup_node_for<Type>();
     const auto *elem = try_resolve(context, *node.info);
     return (elem == nullptr) ? node : *elem;

+ 2 - 2
src/entt/poly/poly.hpp

@@ -8,6 +8,7 @@
 #include <type_traits>
 #include <utility>
 #include "../core/any.hpp"
+#include "../core/concepts.hpp"
 #include "../core/type_info.hpp"
 #include "../core/type_traits.hpp"
 #include "fwd.hpp"
@@ -112,9 +113,8 @@ public:
      * @tparam Type The type for which to generate the virtual table.
      * @return A static virtual table for the given concept and type.
      */
-    template<typename Type>
+    template<cvref_unqualified Type>
     [[nodiscard]] static type instance() noexcept {
-        static_assert(std::is_same_v<Type, std::decay_t<Type>>, "Type differs from its decayed form");
         static const vtable_type vtable = fill_vtable<Type>(std::make_index_sequence<Concept::template impl<Type>::size>{});
 
         if constexpr(is_mono) {

+ 4 - 8
src/entt/signal/dispatcher.hpp

@@ -9,6 +9,7 @@
 #include <vector>
 #include "../container/dense_map.hpp"
 #include "../core/compressed_pair.hpp"
+#include "../core/concepts.hpp"
 #include "../core/fwd.hpp"
 #include "../core/type_info.hpp"
 #include "../stl/functional.hpp"
@@ -28,10 +29,8 @@ struct basic_dispatcher_handler {
     [[nodiscard]] virtual std::size_t size() const noexcept = 0;
 };
 
-template<typename Type, typename Allocator>
+template<cvref_unqualified Type, typename Allocator>
 class dispatcher_handler final: public basic_dispatcher_handler {
-    static_assert(std::is_same_v<Type, std::decay_t<Type>>, "Invalid type");
-
     using alloc_traits = std::allocator_traits<Allocator>;
     using signal_type = sigh<void(Type &), Allocator>;
     using container_type = std::vector<Type, typename alloc_traits::template rebind_alloc<Type>>;
@@ -116,9 +115,8 @@ class basic_dispatcher {
     using container_allocator = alloc_traits::template rebind_alloc<std::pair<const key_type, mapped_type>>;
     using container_type = dense_map<key_type, mapped_type, stl::identity, std::equal_to<>, container_allocator>;
 
-    template<typename Type>
+    template<cvref_unqualified Type>
     [[nodiscard]] handler_type<Type> &assure(const id_type id) {
-        static_assert(std::is_same_v<Type, std::decay_t<Type>>, "Non-decayed types not allowed");
         auto &&ptr = pools.first()[id];
 
         if(!ptr) {
@@ -129,10 +127,8 @@ class basic_dispatcher {
         return static_cast<handler_type<Type> &>(*ptr);
     }
 
-    template<typename Type>
+    template<cvref_unqualified Type>
     [[nodiscard]] const handler_type<Type> *assure(const id_type id) const {
-        static_assert(std::is_same_v<Type, std::decay_t<Type>>, "Non-decayed types not allowed");
-
         if(auto it = pools.first().find(id); it != pools.first().cend()) {
             return static_cast<const handler_type<Type> *>(it->second.get());
         }