Jelajahi Sumber

any: cleanup further

Michele Caini 1 tahun lalu
induk
melakukan
adcf929fdf
2 mengubah file dengan 5 tambahan dan 4 penghapusan
  1. 1 0
      TODO
  2. 4 4
      src/entt/core/any.hpp

+ 1 - 0
TODO

@@ -44,4 +44,5 @@ TODO:
 * built-in no-pagination storage - no_pagination page size as limits::max
 * meta_any ownership construction and from_void
 * sparse_set shrink_to_fit argument for sparse array shrink policy (none, empty, deep, whatever)
+* any cdynamic to support const ownership construction
 * track meta context on meta elements

+ 4 - 4
src/entt/core/any.hpp

@@ -109,9 +109,9 @@ class basic_any {
 
     template<typename Type, typename... Args>
     void initialize([[maybe_unused]] Args &&...args) {
-        using plain_type = std::remove_cv_t<std::remove_reference_t<Type>>;
-
         if constexpr(!std::is_void_v<Type>) {
+            using plain_type = std::remove_cv_t<std::remove_reference_t<Type>>;
+
             info = &type_id<plain_type>();
             vtable = basic_vtable<plain_type>;
 
@@ -178,10 +178,10 @@ public:
      */
     template<typename Type>
     explicit basic_any(std::in_place_t, Type *value)
-        : instance{value} {
+        : instance{} {
         static_assert(!std::is_const_v<Type> && !std::is_void_v<Type>, "Non-const non-void pointer required");
 
-        if(instance != nullptr) {
+        if(value != nullptr) {
             initialize<Type &>(*value);
             mode = any_policy::dynamic;
         }