From 0f718c568b448005bcb6718e7c0f5b6420ace413 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Fri, 26 May 2023 00:28:00 -0700 Subject: Add support for stateful allocators to absl::FixedArray. PiperOrigin-RevId: 535534819 Change-Id: Iccf8da3e0b084131e4c0dba205f3e190d3a66f4e --- absl/container/fixed_array_test.cc | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'absl/container/fixed_array_test.cc') diff --git a/absl/container/fixed_array_test.cc b/absl/container/fixed_array_test.cc index 49598e7a..9dbf2a84 100644 --- a/absl/container/fixed_array_test.cc +++ b/absl/container/fixed_array_test.cc @@ -768,6 +768,22 @@ TEST(AllocatorSupportTest, SizeValAllocConstructor) { } } +TEST(AllocatorSupportTest, PropagatesStatefulAllocator) { + constexpr size_t inlined_size = 4; + using Alloc = absl::container_internal::CountingAllocator; + using AllocFxdArr = absl::FixedArray; + + auto len = inlined_size * 2; + auto val = 0; + int64_t allocated = 0; + AllocFxdArr arr(len, val, Alloc(&allocated)); + + EXPECT_EQ(allocated, len * sizeof(int)); + + AllocFxdArr copy = arr; + EXPECT_EQ(allocated, len * sizeof(int) * 2); +} + #ifdef ABSL_HAVE_ADDRESS_SANITIZER TEST(FixedArrayTest, AddressSanitizerAnnotations1) { absl::FixedArray a(10); -- cgit v1.2.3