Selaa lähdekoodia

test: try to also please g++-7

Michele Caini 4 vuotta sitten
vanhempi
commit
e311ab1605

+ 1 - 0
TODO

@@ -13,6 +13,7 @@ WIP:
 * make pools available (registry/view/group), review operator| for views, make views accept registry to ctor
 * make view.lead() or similar available to return leading pool (useful for mt)
 * dedicated entity storage, in-place O(1) release/destroy for non-orphaned entities
+* non-throwing sparse set emplace (see previous line)
 * custom allocators all over
 
 WIP:

+ 0 - 57
test/entt/entity/custom_allocator.hpp

@@ -1,57 +0,0 @@
-#ifndef ENTT_ENTITY_CUSTOM_ALLOCATOR_HPP
-#define ENTT_ENTITY_CUSTOM_ALLOCATOR_HPP
-
-
-#include <cstddef>
-#include <memory>
-#include <type_traits>
-
-
-namespace test {
-
-
-template<typename Type>
-class custom_allocator: std::allocator<Type> {
-    template<typename Other>
-    friend class custom_allocator;
-
-    using base = std::allocator<Type>;
-
-public:
-    using value_type = Type;
-    using pointer = value_type *;
-    using const_pointer = const value_type *;
-    using void_pointer = void *;
-    using const_void_pointer = const void *;
-    using propagate_on_container_move_assignment = std::true_type;
-    using propagate_on_container_swap = std::true_type;
-
-    custom_allocator() = default;
-
-    template<class Other>
-    custom_allocator(const custom_allocator<Other> &other)
-        : base{static_cast<const std::allocator<Other> &>(other)}
-    {}
-
-    pointer allocate(std::size_t length) {
-        return base::allocate(length);
-    }
-
-    void deallocate(pointer mem, std::size_t length) {
-        base::deallocate(mem, length);
-    }
-
-    bool operator==(const custom_allocator<Type> &) const {
-        return true;
-    }
-
-    bool operator!=(const custom_allocator<Type> &) const {
-        return false;
-    }
-};
-
-
-}
-
-
-#endif

+ 3 - 5
test/entt/entity/sparse_set.cpp

@@ -7,8 +7,6 @@
 #include <gtest/gtest.h>
 #include <entt/entity/entity.hpp>
 #include <entt/entity/sparse_set.hpp>
-#include <entt/entity/fwd.hpp>
-#include "custom_allocator.hpp"
 #include "throwing_allocator.hpp"
 
 struct empty_type {};
@@ -1131,8 +1129,8 @@ TEST(SparseSet, CanModifyDuringIteration) {
 }
 
 TEST(SparseSet, CustomAllocator) {
-    test::custom_allocator<entt::entity> allocator{};
-    entt::basic_sparse_set<entt::entity, test::custom_allocator<entt::entity>> set{allocator};
+    test::throwing_allocator<entt::entity> allocator{};
+    entt::basic_sparse_set<entt::entity, test::throwing_allocator<entt::entity>> set{allocator};
 
     ASSERT_EQ(set.get_allocator(), allocator);
 
@@ -1143,7 +1141,7 @@ TEST(SparseSet, CustomAllocator) {
     set.emplace(entt::entity{0});
     set.emplace(entt::entity{1});
 
-    entt::basic_sparse_set<entt::entity, test::custom_allocator<entt::entity>> other{std::move(set), allocator};
+    entt::basic_sparse_set<entt::entity, test::throwing_allocator<entt::entity>> other{std::move(set), allocator};
 
     ASSERT_TRUE(set.empty());
     ASSERT_FALSE(other.empty());

+ 12 - 0
test/entt/entity/throwing_allocator.hpp

@@ -28,6 +28,10 @@ public:
     using propagate_on_container_swap = std::true_type;
     using exception_type = test_exception;
 
+    template<class Other> struct rebind {
+        using other = throwing_allocator<Other>;
+    };
+
     throwing_allocator() = default;
 
     template<class Other>
@@ -51,6 +55,14 @@ public:
         base::deallocate(mem, length);
     }
 
+    bool operator==(const throwing_allocator<Type> &) const {
+        return true;
+    }
+
+    bool operator!=(const throwing_allocator<Type> &) const {
+        return false;
+    }
+
     static inline bool trigger_on_allocate{};
     static inline bool trigger_after_allocate{};
 };