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

@@ -37,8 +37,7 @@ template <typename T> class mock_allocator {
MOCK_METHOD(void, deallocate, (T*, size_t));
};
template <typename Allocator, bool PropagateOnMove = false>
class allocator_ref {
template <typename Allocator, bool PropagateOnMove = true> class allocator_ref {
private:
Allocator* alloc_;
@@ -50,8 +49,7 @@ class allocator_ref {
public:
using value_type = typename Allocator::value_type;
using propagate_on_container_move_assignment =
typename std::conditional<PropagateOnMove, std::true_type,
std::false_type>::type;
fmt::bool_constant<PropagateOnMove>;
explicit allocator_ref(Allocator* alloc = nullptr) : alloc_(alloc) {}
@@ -70,23 +68,19 @@ class allocator_ref {
}
public:
Allocator* get() const { return alloc_; }
auto get() const -> Allocator* { return alloc_; }
value_type* allocate(size_t n) {
auto allocate(size_t n) -> value_type* {
return std::allocator_traits<Allocator>::allocate(*alloc_, n);
}
void deallocate(value_type* p, size_t n) { alloc_->deallocate(p, n); }
FMT_CONSTEXPR20 friend bool operator==(const allocator_ref& a,
const allocator_ref& b) noexcept {
friend auto operator==(allocator_ref a, allocator_ref b) noexcept -> bool {
if (a.alloc_ == b.alloc_) return true;
if (a.alloc_ == nullptr || b.alloc_ == nullptr) return false;
return *a.alloc_ == *b.alloc_;
return a.alloc_ && b.alloc_ && *a.alloc_ == *b.alloc_;
}
FMT_CONSTEXPR20 friend bool operator!=(const allocator_ref& a,
const allocator_ref& b) noexcept {
friend auto operator!=(allocator_ref a, allocator_ref b) noexcept -> bool {
return !(a == b);
}
};