Explorar o código

memory: class level new/delete support - close #1131

Michele Caini hai 1 ano
pai
achega
d734c92ee4
Modificáronse 2 ficheiros con 12 adicións e 1 borrados
  1. 1 1
      src/entt/core/memory.hpp
  2. 11 0
      test/entt/entity/storage.cpp

+ 1 - 1
src/entt/core/memory.hpp

@@ -275,7 +275,7 @@ constexpr Type make_obj_using_allocator(const Allocator &allocator, Args &&...ar
  */
 template<typename Type, typename Allocator, typename... Args>
 constexpr Type *uninitialized_construct_using_allocator(Type *value, const Allocator &allocator, Args &&...args) {
-    return std::apply([value](auto &&...curr) { return new(value) Type(std::forward<decltype(curr)>(curr)...); }, internal::uses_allocator_construction<Type>::args(allocator, std::forward<Args>(args)...));
+    return std::apply([value](auto &&...curr) { return ::new(value) Type(std::forward<decltype(curr)>(curr)...); }, internal::uses_allocator_construction<Type>::args(allocator, std::forward<Args>(args)...));
 }
 
 } // namespace entt

+ 11 - 0
test/entt/entity/storage.cpp

@@ -15,6 +15,7 @@
 #include "../../common/aggregate.h"
 #include "../../common/config.h"
 #include "../../common/linter.hpp"
+#include "../../common/new_delete.h"
 #include "../../common/pointer_stable.h"
 #include "../../common/throwing_allocator.hpp"
 #include "../../common/throwing_type.hpp"
@@ -1685,6 +1686,16 @@ TEST(Storage, CreateFromConstructor) {
     ASSERT_EQ(pool.get(other).child, static_cast<entt::entity>(entt::null));
 }
 
+TEST(Storage, ClassLevelNewDelete) {
+    entt::storage<test::new_delete> pool;
+    const entt::entity entity{0u};
+
+    // yeah, that's for code coverage purposes only :)
+    pool.emplace(entity, *std::make_unique<test::new_delete>(test::new_delete{3}));
+
+    ASSERT_EQ(pool.get(entity).value, 3);
+}
+
 TYPED_TEST(Storage, CustomAllocator) {
     using value_type = typename TestFixture::type;
     const test::throwing_allocator<entt::entity> allocator{};