/** \brief Aligned allocator class for use with STL containers. Ensures that
* your objects are aligned to N bytes. */
-template <typename T, std::size_t N> class AlignedAllocator {
+template <class T, std::size_t N>
+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;
-
- template <typename U> struct rebind {
- typedef AlignedAllocator<U, N> other;
- };
-
- 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<size_type>::max() / sizeof(value_type);
- }
-
- pointer allocate(size_type size) const {
- return static_cast<pointer>(
- aligned_malloc_internal(size * sizeof(value_type), N));
- }
+ using value_type = T;
- void deallocate(pointer x, size_type) const { aligned_free_internal(x); }
+ AlignedAllocator() noexcept {}
- void construct(pointer x, const value_type &val) const {
- new (x) value_type(val);
- }
+ template <class U, std::size_t N2>
+ AlignedAllocator(const AlignedAllocator<U, N2> &) noexcept {}
- void destroy(pointer p) const { p->~value_type(); }
+ template <class U> struct rebind {
+ using other = AlignedAllocator<U, N>;
+ };
- bool operator==(const AlignedAllocator<T, N> &) const {
- // All instances of AlignedAllocator can dealloc each others' memory.
- return true;
+ T *allocate(std::size_t size) const {
+ size_t alloc_size = size * sizeof(T);
+ return static_cast<T *>(aligned_malloc_internal(alloc_size, N));
}
- bool operator!=(const AlignedAllocator<T, N> &) 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 <class T, class U, std::size_t N, std::size_t N2>
+bool operator==(const AlignedAllocator<T, N> &,
+ const AlignedAllocator<U, N2> &) {
+ return true;
+}
+
+template <class T, class U, std::size_t N, std::size_t N2>
+bool operator!=(const AlignedAllocator<T, N> &a,
+ const AlignedAllocator<U, N2> &b) {
+ return !(a == b);
+}
+
} // namespace ue2
#endif