[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
Tue Feb 18 03:11:48 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:
This seems rather useless. If we don't provide it `allocator_traits` will fall back on the normal `allocate` anyways.
https://github.com/llvm/llvm-project/pull/127321
More information about the libcxx-commits
mailing list