diff --git a/libs/utils/include/utils/Allocator.h b/libs/utils/include/utils/Allocator.h index a16a376dcf..e67a8bfb00 100644 --- a/libs/utils/include/utils/Allocator.h +++ b/libs/utils/include/utils/Allocator.h @@ -739,6 +739,9 @@ public: // from an Arena, avoiding to have to repeat the vector type. STLAllocator(ARENA& arena) : mArena(arena) { } // NOLINT(google-explicit-constructor) + template + explicit STLAllocator(STLAllocator const& rhs) : mArena(rhs.mArena) { } + TYPE* allocate(std::size_t n) { return static_cast(mArena.alloc(n * sizeof(TYPE), alignof(TYPE))); } diff --git a/libs/utils/test/test_Allocators.cpp b/libs/utils/test/test_Allocators.cpp index 746e6740e1..01f5db2c03 100644 --- a/libs/utils/test/test_Allocators.cpp +++ b/libs/utils/test/test_Allocators.cpp @@ -308,6 +308,16 @@ TEST(AllocatorTest, STLAllocator) { EXPECT_TRUE(allocator != allocator2); EXPECT_TRUE(allocator == allocator); + STLAllocator::rebind::other charAllocator(arena); + EXPECT_TRUE(allocator == charAllocator); + + STLAllocator allocatorCopy(allocator); + EXPECT_TRUE(allocator == allocatorCopy); + + STLAllocator allocatorFromCharCopy(charAllocator); + EXPECT_TRUE(allocatorFromCharCopy == charAllocator); + + { #if !defined(WIN32) std::vector> vector(allocator);