Explorar o código

any: let the wrapper decide what it means to be an owner

Michele Caini %!s(int64=4) %!d(string=hai) anos
pai
achega
21ece182f5
Modificáronse 2 ficheiros con 4 adicións e 6 borrados
  1. 0 2
      TODO
  2. 4 4
      src/entt/core/any.hpp

+ 0 - 2
TODO

@@ -4,7 +4,6 @@
 * add examples (and credits) from @alanjfs :)
 * add examples (and credits) from @alanjfs :)
 
 
 WIP:
 WIP:
-* any: avoid operations when trivially-*
 * runtime events (emitter)
 * runtime events (emitter)
 * iterator based try_emplace vs try_insert for perf reasons
 * iterator based try_emplace vs try_insert for perf reasons
 * registry: remove reference to basic_sparse_set<E>
 * registry: remove reference to basic_sparse_set<E>
@@ -12,7 +11,6 @@ WIP:
 * custom allocators all over
 * custom allocators all over
 
 
 WIP:
 WIP:
-* customizable any_vtable, sfinae-friendly definition and op::custom for user-def
 * resource, forward the id to the loader from the cache and if constexpr the call to load, update doc and describe customization points
 * resource, forward the id to the loader from the cache and if constexpr the call to load, update doc and describe customization points
 * add user data to type_info
 * add user data to type_info
 * write documentation for custom storages and views!!
 * write documentation for custom storages and views!!

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

@@ -50,7 +50,7 @@ class basic_any {
         const Type *element = nullptr;
         const Type *element = nullptr;
 
 
         if constexpr(in_situ<Type>) {
         if constexpr(in_situ<Type>) {
-            element = (value.mode == policy::owner) ? ENTT_LAUNDER(reinterpret_cast<const Type *>(&value.storage)) : static_cast<const Type *>(value.instance);
+            element = value.owner() ? ENTT_LAUNDER(reinterpret_cast<const Type *>(&value.storage)) : static_cast<const Type *>(value.instance);
         } else {
         } else {
             element = static_cast<const Type *>(value.instance);
             element = static_cast<const Type *>(value.instance);
         }
         }
@@ -63,7 +63,7 @@ class basic_any {
             break;
             break;
         case operation::move:
         case operation::move:
             if constexpr(in_situ<Type>) {
             if constexpr(in_situ<Type>) {
-                if(value.mode == policy::owner) {
+                if(value.owner()) {
                     return new(&static_cast<basic_any *>(const_cast<void *>(other))->storage) Type{std::move(*const_cast<Type *>(element))};
                     return new(&static_cast<basic_any *>(const_cast<void *>(other))->storage) Type{std::move(*const_cast<Type *>(element))};
                 }
                 }
             }
             }
@@ -204,7 +204,7 @@ public:
 
 
     /*! @brief Frees the internal storage, whatever it means. */
     /*! @brief Frees the internal storage, whatever it means. */
     ~basic_any() {
     ~basic_any() {
-        if(vtable && mode == policy::owner) {
+        if(vtable && owner()) {
             vtable(operation::destroy, *this, nullptr);
             vtable(operation::destroy, *this, nullptr);
         }
         }
     }
     }
@@ -337,7 +337,7 @@ public:
 
 
     /*! @brief Destroys contained object */
     /*! @brief Destroys contained object */
     void reset() {
     void reset() {
-        if(vtable && mode == policy::owner) {
+        if(vtable && owner()) {
             vtable(operation::destroy, *this, nullptr);
             vtable(operation::destroy, *this, nullptr);
         }
         }