Browse Source

sigh: rebind allocator internally

Michele Caini 4 years ago
parent
commit
bdb7763237
2 changed files with 6 additions and 3 deletions
  1. 4 1
      src/entt/signal/sigh.hpp
  2. 2 2
      test/entt/signal/sigh.cpp

+ 4 - 1
src/entt/signal/sigh.hpp

@@ -57,6 +57,9 @@ class sigh<Ret(Args...), Allocator> {
     /*! @brief A sink is allowed to modify a signal. */
     friend class sink<sigh<Ret(Args...), Allocator>>;
 
+    using alloc_traits = std::allocator_traits<Allocator>;
+    using container_type = std::vector<delegate<Ret(Args...)>, typename alloc_traits::template rebind_alloc<delegate<Ret(Args...)>>>;
+
 public:
     /*! @brief Allocator type. */
     using allocator_type = Allocator;
@@ -215,7 +218,7 @@ public:
     }
 
 private:
-    std::vector<delegate<Ret(Args...)>, Allocator> calls;
+    container_type calls;
 };
 
 /**

+ 2 - 2
test/entt/signal/sigh.cpp

@@ -1,8 +1,8 @@
+#include <memory>
 #include <utility>
 #include <vector>
 #include <gtest/gtest.h>
 #include <entt/signal/sigh.hpp>
-#include "../common/throwing_allocator.hpp"
 
 struct sigh_listener {
     static void f(int &v) {
@@ -531,7 +531,7 @@ TEST_F(SigH, UnboundMemberFunction) {
 }
 
 TEST_F(SigH, CustomAllocator) {
-    test::throwing_allocator<entt::delegate<void(int)>> allocator;
+    std::allocator<void (*)(int)> allocator;
 
     auto test = [&](auto curr) {
         ASSERT_EQ(curr.get_allocator(), allocator);