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) + allocator() = default; + template + constexpr allocator(const allocator&) noexcept { } + + [[nodiscard]] T *allocate(std::size_t n) { - if(n > std::numeric_limits::max() / sizeof(T)) - throw std::bad_alloc(); - - void *ret{al_malloc(alignment, n*sizeof(T))}; - if(!ret) throw std::bad_alloc(); - return static_cast(ret); + 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