From c6c50484160435ee96e51eece154013fe6e48237 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Wed, 11 Sep 2019 03:22:10 -0700 Subject: Don't inherit for the allocator --- common/almalloc.h | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/common/almalloc.h b/common/almalloc.h index ca92316a..785592bd 100644 --- a/common/almalloc.h +++ b/common/almalloc.h @@ -34,36 +34,32 @@ namespace al { #define REQUIRES(...) typename std::enable_if<(__VA_ARGS__),int>::type = 0 -template -struct allocator : public std::allocator { - using size_type = size_t; - using pointer = T*; - using const_pointer = const T*; +template +struct allocator { + using value_type = T; + using is_always_equal = std::true_type; template struct rebind { - using other = allocator; + using other = allocator; }; - pointer allocate(size_type n, const void* = nullptr) - { - if(n > std::numeric_limits::max() / sizeof(T)) - throw std::bad_alloc(); + allocator() = default; + template + constexpr allocator(const allocator&) noexcept { } - void *ret{al_malloc(alignment, n*sizeof(T))}; - if(!ret) throw std::bad_alloc(); - return static_cast(ret); + [[nodiscard]] T *allocate(std::size_t n) + { + if(n > std::numeric_limits::max() / sizeof(T)) throw std::bad_alloc(); + if(auto p = static_cast(al_malloc(alignment, n*sizeof(T)))) return p; + throw std::bad_alloc(); } - - void deallocate(pointer p, size_type) - { al_free(p); } - - allocator() : std::allocator() { } - allocator(const allocator &a) : std::allocator(a) { } - template - allocator(const allocator &a) : std::allocator(a) - { } + void deallocate(T *p, std::size_t) noexcept { al_free(p); } }; +template +bool operator==(const allocator&, const allocator&) noexcept { return true; } +template +bool operator!=(const allocator&, const allocator&) noexcept { return false; } template inline T* assume_aligned(T *ptr) noexcept -- cgit v1.2.3