[libcxx-commits] [libcxx] [libc++] Fix shrink_to_fit to swap buffer only when capacity is strictly smaller (PR #127321)

Nikolas Klauser via libcxx-commits libcxx-commits at lists.llvm.org
Wed Feb 19 06:15:59 PST 2025


================
@@ -49,4 +50,89 @@ TEST_CONSTEXPR_CXX20 bool operator==(increasing_allocator<T>, increasing_allocat
   return true;
 }
 
+template <std::size_t MinAllocSize, typename T>
+class min_size_allocator {
+public:
+  using value_type     = T;
+  min_size_allocator() = default;
+
+  template <typename U>
+  TEST_CONSTEXPR_CXX20 min_size_allocator(const min_size_allocator<MinAllocSize, U>&) TEST_NOEXCEPT {}
+
+#if TEST_STD_VER >= 23
+  TEST_CONSTEXPR_CXX23 std::allocation_result<T*> allocate_at_least(std::size_t n) {
+    if (n < MinAllocSize)
+      n = MinAllocSize;
+    return std::allocator<T>{}.allocate_at_least(n);
+  }
+#endif // TEST_STD_VER >= 23
----------------
philnik777 wrote:

>From our discussion: `std::allocator` provides both `allocate` and `allocte_at_least`, but there doesn't seem to be a good reason that `std::allocator` should provide it. Given that, I don't think we need to provide it here.

https://github.com/llvm/llvm-project/pull/127321


More information about the libcxx-commits mailing list