diff --git a/src/util/alloc.h b/src/util/alloc.h index ab996a8d..191bc387 100644 --- a/src/util/alloc.h +++ b/src/util/alloc.h @@ -78,51 +78,42 @@ void aligned_free_internal(void *ptr); /** \brief Aligned allocator class for use with STL containers. Ensures that * your objects are aligned to N bytes. */ -template class AlignedAllocator { +template +class AlignedAllocator { public: - typedef T value_type; - typedef std::size_t size_type; - typedef std::ptrdiff_t difference_type; - typedef T *pointer; - typedef const T *const_pointer; - typedef T &reference; - typedef const T &const_reference; + using value_type = T; - template struct rebind { - typedef AlignedAllocator other; + AlignedAllocator() noexcept {} + + template + AlignedAllocator(const AlignedAllocator &) noexcept {} + + template struct rebind { + using other = AlignedAllocator; }; - pointer address(reference x) const { return &x; } - const_pointer address(const_reference x) const { return &x; } - - size_type max_size() const { - return std::numeric_limits::max() / sizeof(value_type); + T *allocate(std::size_t size) const { + size_t alloc_size = size * sizeof(T); + return static_cast(aligned_malloc_internal(alloc_size, N)); } - pointer allocate(size_type size) const { - return static_cast( - aligned_malloc_internal(size * sizeof(value_type), N)); - } - - void deallocate(pointer x, size_type) const { aligned_free_internal(x); } - - void construct(pointer x, const value_type &val) const { - new (x) value_type(val); - } - - void destroy(pointer p) const { p->~value_type(); } - - bool operator==(const AlignedAllocator &) const { - // All instances of AlignedAllocator can dealloc each others' memory. - return true; - } - - bool operator!=(const AlignedAllocator &) const { - // All instances of AlignedAllocator can dealloc each others' memory. - return false; + void deallocate(T *x, std::size_t) const noexcept { + aligned_free_internal(x); } }; +template +bool operator==(const AlignedAllocator &, + const AlignedAllocator &) { + return true; +} + +template +bool operator!=(const AlignedAllocator &a, + const AlignedAllocator &b) { + return !(a == b); +} + } // namespace ue2 #endif