Minor cleanup

This commit is contained in:
Victor Zverovich
2025-08-16 07:42:37 -07:00
parent e9ddc97b9a
commit 7ffc3ca15b
3 changed files with 35 additions and 52 deletions

View File

@@ -752,12 +752,11 @@ template <typename T> struct allocator : private std::decay<void> {
void deallocate(T* p, size_t) { std::free(p); }
FMT_CONSTEXPR20 friend bool operator==(allocator, allocator) noexcept {
constexpr friend auto operator==(allocator, allocator) noexcept -> bool {
return true; // All instances of this allocator are equivalent.
}
FMT_CONSTEXPR20 friend bool operator!=(allocator a, allocator b) noexcept {
return !(a == b);
constexpr friend auto operator!=(allocator, allocator) noexcept -> bool {
return false;
}
};
@@ -834,42 +833,32 @@ class basic_memory_buffer : public detail::buffer<T> {
FMT_CONSTEXPR20 ~basic_memory_buffer() { deallocate(); }
private:
template <typename Alloc = Allocator>
FMT_CONSTEXPR20
typename std::enable_if<std::allocator_traits<Alloc>::
propagate_on_container_move_assignment::value,
bool>::type
allocator_move_impl(basic_memory_buffer& other) {
template <typename Alloc = Allocator,
FMT_ENABLE_IF(std::allocator_traits<Alloc>::
propagate_on_container_move_assignment::value)>
FMT_CONSTEXPR20 auto move_alloc(basic_memory_buffer& other) -> bool {
alloc_ = std::move(other.alloc_);
return true;
}
// If the allocator does not propagate,
// then copy the content from source buffer.
template <typename Alloc = Allocator>
FMT_CONSTEXPR20
typename std::enable_if<!std::allocator_traits<Alloc>::
propagate_on_container_move_assignment::value,
bool>::type
allocator_move_impl(basic_memory_buffer& other) {
// If the allocator does not propagate then copy the data from other.
template <typename Alloc = Allocator,
FMT_ENABLE_IF(!std::allocator_traits<Alloc>::
propagate_on_container_move_assignment::value)>
FMT_CONSTEXPR20 auto move_alloc(basic_memory_buffer& other) -> bool {
T* data = other.data();
if (alloc_ != other.alloc_ && data != other.store_) {
size_t size = other.size();
// Perform copy operation, allocators are different
this->resize(size);
detail::copy<T>(data, data + size, this->data());
return false;
}
return true;
if (alloc_ == other.alloc_ || data == other.store_) return true;
size_t size = other.size();
// Perform copy operation, allocators are different.
this->resize(size);
detail::copy<T>(data, data + size, this->data());
return false;
}
// Move data from other to this buffer.
FMT_CONSTEXPR20 void move(basic_memory_buffer& other) {
T* data = other.data();
size_t size = other.size(), capacity = other.capacity();
// Replicate the behaviour of std library containers
if (!allocator_move_impl(other)) {
return;
}
if (!move_alloc(other)) return;
if (data == other.store_) {
this->set(store_, capacity);
detail::copy<T>(other.store_, other.store_ + size, store_);