Use std::allocator_traits (#3804)

Signed-off-by: Vladislav Shchapov <vladislav@shchapov.ru>
This commit is contained in:
Vladislav Shchapov
2024-01-13 08:48:37 -08:00
committed by GitHub
parent df6a3564b0
commit 21b0458291
2 changed files with 30 additions and 28 deletions
+9 -14
View File
@@ -43,9 +43,13 @@
#include <cstring> // std::memcpy
#include <initializer_list> // std::initializer_list
#include <limits> // std::numeric_limits
#include <stdexcept> // std::runtime_error
#include <string> // std::string
#include <system_error> // std::system_error
#if defined(__GLIBCXX__) && !defined(_GLIBCXX_USE_DUAL_ABI)
// Workaround for pre gcc 5 libstdc++.
# include <memory> // std::allocator_traits
#endif
#include <stdexcept> // std::runtime_error
#include <string> // std::string
#include <system_error> // std::system_error
#include "base.h"
@@ -509,14 +513,6 @@ FMT_INLINE void assume(bool condition) {
#endif
}
template <typename Allocator, typename Enable = void> struct allocator_size {
using type = size_t;
};
template <typename Allocator>
struct allocator_size<Allocator, void_t<typename Allocator::size_type>> {
using type = typename Allocator::size_type;
};
template <typename Char, typename InputIt>
auto copy_str(InputIt begin, InputIt end, appender out) -> appender {
get_container(out).append(begin, end);
@@ -915,9 +911,8 @@ class basic_memory_buffer : public detail::buffer<T> {
static FMT_CONSTEXPR20 void grow(detail::buffer<T>& buf, size_t size) {
detail::abort_fuzzing_if(size > 5000);
auto& self = static_cast<basic_memory_buffer&>(buf);
constexpr size_t max_size =
detail::max_value<typename detail::allocator_size<Allocator>::type>() /
sizeof(T);
const size_t max_size =
std::allocator_traits<Allocator>::max_size(self.alloc_);
size_t old_capacity = buf.capacity();
size_t new_capacity = old_capacity + old_capacity / 2;
if (size > new_capacity)