瀏覽代碼

*: minor changes

Michele Caini 5 年之前
父節點
當前提交
3dac65a012
共有 4 個文件被更改,包括 16 次插入18 次删除
  1. 7 9
      src/entt/core/any.hpp
  2. 5 5
      src/entt/entity/snapshot.hpp
  3. 2 2
      src/entt/entity/view_pack.hpp
  4. 2 2
      src/entt/meta/internal.hpp

+ 7 - 9
src/entt/core/any.hpp

@@ -72,7 +72,7 @@ class any {
             case operation::CADDR:
                 return instance;
             case operation::REF:
-                as_any(to).vtable = basic_vtable<std::add_lvalue_reference_t<Type>>;
+                as_any(to).vtable = basic_vtable<Type &>;
                 as_any(to).instance = instance;
                 break;
             case operation::TYPE:
@@ -94,7 +94,7 @@ class any {
             case operation::CADDR:
                 return from.instance;
             case operation::REF:
-                as_any(to).vtable = basic_vtable<std::add_lvalue_reference_t<Type>>;
+                as_any(to).vtable = basic_vtable<Type &>;
                 as_any(to).instance = from.instance;
                 break;
             case operation::TYPE:
@@ -140,7 +140,7 @@ public:
      */
     template<typename Type>
     any(std::reference_wrapper<Type> value) ENTT_NOEXCEPT
-        : vtable{&basic_vtable<std::add_lvalue_reference_t<Type>>},
+        : vtable{&basic_vtable<Type &>},
           instance{&value.get()}
     {}
 
@@ -279,6 +279,7 @@ Type any_cast(const any &data) ENTT_NOEXCEPT {
 /*! @copydoc any_cast */
 template<typename Type>
 Type any_cast(any &data) ENTT_NOEXCEPT {
+    // forces const on non-reference types to make them work also with wrappers for const references
     auto * const instance = any_cast<std::conditional_t<std::is_reference_v<Type>, std::remove_reference_t<Type>, const Type>>(&data);
     ENTT_ASSERT(instance);
     return static_cast<Type>(*instance);
@@ -288,6 +289,7 @@ Type any_cast(any &data) ENTT_NOEXCEPT {
 /*! @copydoc any_cast */
 template<typename Type>
 Type any_cast(any &&data) ENTT_NOEXCEPT {
+    // forces const on non-reference types to make them work also with wrappers for const references
     auto * const instance = any_cast<std::conditional_t<std::is_reference_v<Type>, std::remove_reference_t<Type>, const Type>>(&data);
     ENTT_ASSERT(instance);
     return static_cast<Type>(std::move(*instance));
@@ -304,12 +306,8 @@ const Type * any_cast(const any *data) ENTT_NOEXCEPT {
 /*! @copydoc any_cast */
 template<typename Type>
 Type * any_cast(any *data) ENTT_NOEXCEPT {
-    if constexpr(std::is_const_v<Type>) {
-        // last attempt to make wrappers for const references return their values
-        return any_cast<std::remove_const_t<Type>>(&std::as_const(*data));
-    } else {
-        return (data->type() == type_id<Type>() ? static_cast<Type *>(data->data()) : nullptr);
-    }
+    // last attempt to make wrappers for const references return their values
+    return (data->type() == type_id<Type>() ? static_cast<Type *>(static_cast<constness_as_t<any, Type> *>(data)->data()) : nullptr);
 }
 
 

+ 5 - 5
src/entt/entity/snapshot.hpp

@@ -48,17 +48,17 @@ class basic_snapshot {
         }
     }
 
-    template<typename... Component, typename Archive, typename It, std::size_t... Indexes>
-    void component(Archive &archive, It first, It last, std::index_sequence<Indexes...>) const {
-        std::array<std::size_t, sizeof...(Indexes)> size{};
+    template<typename... Component, typename Archive, typename It, std::size_t... Index>
+    void component(Archive &archive, It first, It last, std::index_sequence<Index...>) const {
+        std::array<std::size_t, sizeof...(Index)> size{};
         auto begin = first;
 
         while(begin != last) {
             const auto entt = *(begin++);
-            ((reg->template has<Component>(entt) ? ++size[Indexes] : size[Indexes]), ...);
+            ((reg->template has<Component>(entt) ? ++size[Index] : size[Index]), ...);
         }
 
-        (get<Component>(archive, size[Indexes], first, last), ...);
+        (get<Component>(archive, size[Index], first, last), ...);
     }
 
 public:

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

@@ -305,9 +305,9 @@ public:
         if constexpr(sizeof...(Comp) == 0) {
             return component;
         } else if constexpr(sizeof...(Comp) == 1) {
-            return (std::get<std::add_lvalue_reference_t<Comp>>(component), ...);
+            return (std::get<Comp &>(component), ...);
         } else {
-            return std::forward_as_tuple(std::get<std::add_lvalue_reference_t<Comp>>(component)...);
+            return std::forward_as_tuple(std::get<Comp &>(component)...);
         }
     }
 

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

@@ -261,8 +261,8 @@ public:
                 return extent(dim, std::make_index_sequence<std::rank_v<Type>>{});
             },
             &compare, // workaround for an issue with VS2017
-            &meta_node<std::remove_const_t<std::remove_pointer_t<Type>>>::resolve,
-            &meta_node<std::remove_const_t<std::remove_extent_t<Type>>>::resolve
+            &meta_node<std::remove_cv_t<std::remove_pointer_t<Type>>>::resolve,
+            &meta_node<std::remove_cv_t<std::remove_extent_t<Type>>>::resolve
         };
 
         return &node;