Просмотр исходного кода

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

Michele Caini 4 лет назад
Родитель
Сommit
21ece182f5
2 измененных файлов с 4 добавлено и 6 удалено
  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 :)
 
 WIP:
-* any: avoid operations when trivially-*
 * runtime events (emitter)
 * iterator based try_emplace vs try_insert for perf reasons
 * registry: remove reference to basic_sparse_set<E>
@@ -12,7 +11,6 @@ WIP:
 * custom allocators all over
 
 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
 * add user data to type_info
 * 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;
 
         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 {
             element = static_cast<const Type *>(value.instance);
         }
@@ -63,7 +63,7 @@ class basic_any {
             break;
         case operation::move:
             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))};
                 }
             }
@@ -204,7 +204,7 @@ public:
 
     /*! @brief Frees the internal storage, whatever it means. */
     ~basic_any() {
-        if(vtable && mode == policy::owner) {
+        if(vtable && owner()) {
             vtable(operation::destroy, *this, nullptr);
         }
     }
@@ -337,7 +337,7 @@ public:
 
     /*! @brief Destroys contained object */
     void reset() {
-        if(vtable && mode == policy::owner) {
+        if(vtable && owner()) {
             vtable(operation::destroy, *this, nullptr);
         }