Explorar el Código

any: use std::addressof to get the address of an object reliably

Michele Caini hace 5 años
padre
commit
bf6576f5af
Se han modificado 3 ficheros con 6 adiciones y 8 borrados
  1. 3 2
      TODO
  2. 2 1
      src/entt/core/any.hpp
  3. 1 5
      src/entt/meta/meta.hpp

+ 3 - 2
TODO

@@ -7,15 +7,16 @@
 * custom pools example (multi instance, tables, enable/disable, and so on...)
 
 WIP:
+* HP: scheduler, use any (or poly?) instead of unique_ptr
+* HP: resource, forward the id to the loader from the cache and if constexpr the call to load, update doc and describe customization points
+* HP: make it possible to create views of the type `view<T, T>`, add get by index and such, allow to register custom pools by name with the registry
 * HP: add user data to type_info
 * HP: make pools available (registry/view/group), review operator| for views
-* HP: resource, forward the id to the loader from the cache and if constexpr the call to load, update doc and describe customization points
 * HP: any_vector for context variables
 * HP: make const registry::view thread safe, switch to a view<T...>{registry} model (long term goal)
 * HP: weak reference wrapper example with custom storage
 * HP: paginate pools
 * HP: headless (sparse set only) view
-* HP: scheduler, use any instead of unique_ptr
 * HP: write documentation for custom storages and views!!
 * HP: registry: use a poly object for pools, no more pool_data type.
 * HP: make runtime views use opaque storage and therefore return also elements.

+ 2 - 1
src/entt/core/any.hpp

@@ -4,6 +4,7 @@
 
 #include <cstddef>
 #include <functional>
+#include <memory>
 #include <new>
 #include <type_traits>
 #include <utility>
@@ -178,7 +179,7 @@ public:
         if constexpr(!std::is_void_v<Type>) {
             if constexpr(std::is_lvalue_reference_v<Type>) {
                 static_assert(sizeof...(Args) == 1u && (std::is_lvalue_reference_v<Args> && ...));
-                instance = (&args, ...);
+                instance = (std::addressof(args), ...);
             } else if constexpr(in_situ<Type>) {
                 new (&storage) Type(std::forward<Args>(args)...);
             } else {

+ 1 - 5
src/entt/meta/meta.hpp

@@ -178,11 +178,7 @@ class meta_any {
             if constexpr(std::is_void_v<Type>) {
                 static_cast<meta_any *>(to)->emplace<void>();
             } else {
-                static_cast<meta_any *>(to)->storage = (op == operation::REF ? const_cast<any &>(from).as_ref() : from.as_ref());
-                static_cast<meta_any *>(to)->node = internal::meta_info<Type>::resolve();
-                static_cast<meta_any *>(to)->vtable = (op == operation::REF ? &basic_vtable<Type &> : &basic_vtable<const base_type &>);
-                // can't do this because apple clang overrides __bit_reference<...>::operator& to return a __bit_iterator by copy (https://opensource.apple.com/source/libcpp/libcpp-31/include/__bit_reference.auto.html)
-                // *static_cast<meta_any *>(to) = (op == operation::REF ? meta_any{std::ref(any_cast<Type &>(const_cast<any &>(from)))} : meta_any{std::cref(any_cast<const base_type &>(from))});
+                *static_cast<meta_any *>(to) = (op == operation::REF ? meta_any{std::ref(any_cast<Type &>(const_cast<any &>(from)))} : meta_any{std::cref(any_cast<const base_type &>(from))});
             }
             break;
         case operation::DEREF: