diff options
author | Benjamin Barenblat <bbaren@google.com> | 2024-05-08 10:59:21 -0400 |
---|---|---|
committer | Benjamin Barenblat <bbaren@google.com> | 2024-05-08 10:59:21 -0400 |
commit | d8e2b896d5e3c1ebf2d6d0d37bd9e7a1b59e0b99 (patch) | |
tree | 33d0793fcdd3615f21e5b4f0e50ae20811a5bde5 /absl/container/internal/container_memory_test.cc | |
parent | 57fc09f12cfb9642e7ebd4ca3c64d07154d2de9a (diff) | |
parent | d7aaad83b488fd62bd51c81ecf16cd938532cc0a (diff) | |
download | abseil-d8e2b896d5e3c1ebf2d6d0d37bd9e7a1b59e0b99.tar.gz abseil-d8e2b896d5e3c1ebf2d6d0d37bd9e7a1b59e0b99.tar.bz2 abseil-d8e2b896d5e3c1ebf2d6d0d37bd9e7a1b59e0b99.zip |
Merge new upstream LTS 20240116.2
Diffstat (limited to 'absl/container/internal/container_memory_test.cc')
-rw-r--r-- | absl/container/internal/container_memory_test.cc | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/absl/container/internal/container_memory_test.cc b/absl/container/internal/container_memory_test.cc index fb9c4dde..90d64bf5 100644 --- a/absl/container/internal/container_memory_test.cc +++ b/absl/container/internal/container_memory_test.cc @@ -14,15 +14,20 @@ #include "absl/container/internal/container_memory.h" +#include <cstddef> #include <cstdint> +#include <memory> #include <tuple> +#include <type_traits> #include <typeindex> #include <typeinfo> #include <utility> #include "gmock/gmock.h" #include "gtest/gtest.h" +#include "absl/base/no_destructor.h" #include "absl/container/internal/test_instance_tracker.h" +#include "absl/meta/type_traits.h" #include "absl/strings/string_view.h" namespace absl { @@ -54,7 +59,7 @@ TEST(Memory, AlignmentSmallerThanBase) { } std::map<std::type_index, int>& AllocationMap() { - static auto* map = new std::map<std::type_index, int>; + static absl::NoDestructor<std::map<std::type_index, int>> map; return *map; } @@ -219,8 +224,7 @@ TEST(DecomposePair, NotDecomposable) { ADD_FAILURE() << "Must not be called"; return 'A'; }; - EXPECT_STREQ("not decomposable", - TryDecomposePair(f)); + EXPECT_STREQ("not decomposable", TryDecomposePair(f)); EXPECT_STREQ("not decomposable", TryDecomposePair(f, std::piecewise_construct, std::make_tuple(), std::make_tuple(0.5))); @@ -251,6 +255,31 @@ TEST(MapSlotPolicy, ConstKeyAndValue) { EXPECT_EQ(tracker.copies(), 0); } +TEST(MapSlotPolicy, TransferReturnsTrue) { + { + using slot_policy = map_slot_policy<int, float>; + EXPECT_TRUE( + (std::is_same<decltype(slot_policy::transfer<std::allocator<char>>( + nullptr, nullptr, nullptr)), + std::true_type>::value)); + } + { + struct NonRelocatable { + NonRelocatable() = default; + NonRelocatable(NonRelocatable&&) {} + NonRelocatable& operator=(NonRelocatable&&) { return *this; } + void* self = nullptr; + }; + + EXPECT_FALSE(absl::is_trivially_relocatable<NonRelocatable>::value); + using slot_policy = map_slot_policy<int, NonRelocatable>; + EXPECT_TRUE( + (std::is_same<decltype(slot_policy::transfer<std::allocator<char>>( + nullptr, nullptr, nullptr)), + std::false_type>::value)); + } +} + } // namespace } // namespace container_internal ABSL_NAMESPACE_END |