Browse Source

storage: removed const T specialization for storage_traits

Michele Caini 5 years ago
parent
commit
0038728be3

+ 2 - 2
src/entt/entity/group.hpp

@@ -69,7 +69,7 @@ class basic_group<Entity, exclude_t<Exclude...>, get_t<Get...>> final {
     friend class basic_registry<Entity>;
     friend class basic_registry<Entity>;
 
 
     template<typename Component>
     template<typename Component>
-    using storage_type = typename storage_traits<Entity, Component>::storage_type;
+    using storage_type = constness_as_t<typename storage_traits<Entity, std::remove_const_t<Component>>::storage_type, Component>;
 
 
     class iterable_group final {
     class iterable_group final {
         friend class basic_group<Entity, exclude_t<Exclude...>, get_t<Get...>>;
         friend class basic_group<Entity, exclude_t<Exclude...>, get_t<Get...>>;
@@ -574,7 +574,7 @@ class basic_group<Entity, exclude_t<Exclude...>, get_t<Get...>, Owned...> final
     friend class basic_registry<Entity>;
     friend class basic_registry<Entity>;
 
 
     template<typename Component>
     template<typename Component>
-    using storage_type = typename storage_traits<Entity, Component>::storage_type;
+    using storage_type = constness_as_t<typename storage_traits<Entity, std::remove_const_t<Component>>::storage_type, Component>;
 
 
     class iterable_group final {
     class iterable_group final {
         friend class basic_group<Entity, exclude_t<Exclude...>, get_t<Get...>, Owned...>;
         friend class basic_group<Entity, exclude_t<Exclude...>, get_t<Get...>, Owned...>;

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

@@ -14,6 +14,7 @@
 #include "../core/algorithm.hpp"
 #include "../core/algorithm.hpp"
 #include "../core/fwd.hpp"
 #include "../core/fwd.hpp"
 #include "../core/type_info.hpp"
 #include "../core/type_info.hpp"
+#include "../core/type_traits.hpp"
 #include "entity.hpp"
 #include "entity.hpp"
 #include "fwd.hpp"
 #include "fwd.hpp"
 #include "group.hpp"
 #include "group.hpp"
@@ -42,7 +43,7 @@ class basic_registry {
     using traits_type = entt_traits<Entity>;
     using traits_type = entt_traits<Entity>;
 
 
     template<typename Component>
     template<typename Component>
-    using storage_type = typename storage_traits<Entity, Component>::storage_type;
+    using storage_type = constness_as_t<typename storage_traits<Entity, std::remove_const_t<Component>>::storage_type, Component>;
 
 
     struct pool_data {
     struct pool_data {
         type_info info{};
         type_info info{};

+ 0 - 8
src/entt/entity/storage.hpp

@@ -806,14 +806,6 @@ struct storage_traits {
 };
 };
 
 
 
 
-/*! @copydoc storage_traits */
-template<typename Entity, typename Type>
-struct storage_traits<Entity, const Type> {
-    /*! @brief Resulting type after component-to-storage conversion. */
-    using storage_type = std::add_const_t<typename storage_traits<Entity, std::remove_const_t<Type>>::storage_type>;
-};
-
-
 /**
 /**
  * @brief Gets the element associated with an entity from a storage, if any.
  * @brief Gets the element associated with an entity from a storage, if any.
  * @tparam Type Storage type.
  * @tparam Type Storage type.

+ 2 - 2
src/entt/entity/view.hpp

@@ -69,7 +69,7 @@ class basic_view<Entity, exclude_t<Exclude...>, Component...> final {
     friend class basic_registry<Entity>;
     friend class basic_registry<Entity>;
 
 
     template<typename Comp>
     template<typename Comp>
-    using storage_type = typename storage_traits<Entity, Comp>::storage_type;
+    using storage_type = constness_as_t<typename storage_traits<Entity, std::remove_const_t<Comp>>::storage_type, Comp>;
 
 
     using unchecked_type = std::array<const basic_sparse_set<Entity> *, (sizeof...(Component) - 1)>;
     using unchecked_type = std::array<const basic_sparse_set<Entity> *, (sizeof...(Component) - 1)>;
 
 
@@ -558,7 +558,7 @@ class basic_view<Entity, exclude_t<>, Component> final {
     /*! @brief A registry is allowed to create views. */
     /*! @brief A registry is allowed to create views. */
     friend class basic_registry<Entity>;
     friend class basic_registry<Entity>;
 
 
-    using storage_type = typename storage_traits<Entity, Component>::storage_type;
+    using storage_type = constness_as_t<typename storage_traits<Entity, std::remove_const_t<Component>>::storage_type, Component>;
 
 
     class iterable_view {
     class iterable_view {
         friend class basic_view<Entity, exclude_t<>, Component>;
         friend class basic_view<Entity, exclude_t<>, Component>;