aboutsummaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2019-09-11 03:22:10 -0700
committerChris Robinson <[email protected]>2019-09-11 03:22:10 -0700
commitc6c50484160435ee96e51eece154013fe6e48237 (patch)
tree929cfae475ed417fac0afd26e85edc5fd1273f9f /common
parent65374dc5d00a2fa64657d4310f7a27c09eaa4c9a (diff)
Don't inherit for the allocator
Diffstat (limited to 'common')
-rw-r--r--common/almalloc.h40
1 files 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<typename T, size_t alignment=alignof(T)>
-struct allocator : public std::allocator<T> {
- using size_type = size_t;
- using pointer = T*;
- using const_pointer = const T*;
+template<typename T, std::size_t alignment=alignof(T)>
+struct allocator {
+ using value_type = T;
+ using is_always_equal = std::true_type;
template<typename U>
struct rebind {
- using other = allocator<U, alignment>;
+ using other = allocator<U, (alignment<alignof(U))?alignof(U):alignment>;
};
- pointer allocate(size_type n, const void* = nullptr)
- {
- if(n > std::numeric_limits<size_t>::max() / sizeof(T))
- throw std::bad_alloc();
+ allocator() = default;
+ template<typename U>
+ constexpr allocator(const allocator<U>&) noexcept { }
- void *ret{al_malloc(alignment, n*sizeof(T))};
- if(!ret) throw std::bad_alloc();
- return static_cast<pointer>(ret);
+ [[nodiscard]] T *allocate(std::size_t n)
+ {
+ if(n > std::numeric_limits<std::size_t>::max() / sizeof(T)) throw std::bad_alloc();
+ if(auto p = static_cast<T*>(al_malloc(alignment, n*sizeof(T)))) return p;
+ throw std::bad_alloc();
}
-
- void deallocate(pointer p, size_type)
- { al_free(p); }
-
- allocator() : std::allocator<T>() { }
- allocator(const allocator &a) : std::allocator<T>(a) { }
- template<class U>
- allocator(const allocator<U,alignment> &a) : std::allocator<T>(a)
- { }
+ void deallocate(T *p, std::size_t) noexcept { al_free(p); }
};
+template<typename T, typename U>
+bool operator==(const allocator<T>&, const allocator<U>&) noexcept { return true; }
+template<typename T, typename U>
+bool operator!=(const allocator<T>&, const allocator<U>&) noexcept { return false; }
template<size_t alignment, typename T>
inline T* assume_aligned(T *ptr) noexcept