summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/common')
-rw-r--r--src/common/alignment.h47
1 files changed, 4 insertions, 43 deletions
diff --git a/src/common/alignment.h b/src/common/alignment.h
index b37044bb6..4025ba651 100644
--- a/src/common/alignment.h
+++ b/src/common/alignment.h
@@ -3,7 +3,6 @@
3#pragma once 3#pragma once
4 4
5#include <cstddef> 5#include <cstddef>
6#include <memory>
7#include <type_traits> 6#include <type_traits>
8 7
9namespace Common { 8namespace Common {
@@ -54,66 +53,28 @@ public:
54 using size_type = std::size_t; 53 using size_type = std::size_t;
55 using difference_type = std::ptrdiff_t; 54 using difference_type = std::ptrdiff_t;
56 55
57 using pointer = T*;
58 using const_pointer = const T*;
59
60 using reference = T&;
61 using const_reference = const T&;
62
63 using propagate_on_container_copy_assignment = std::true_type; 56 using propagate_on_container_copy_assignment = std::true_type;
64 using propagate_on_container_move_assignment = std::true_type; 57 using propagate_on_container_move_assignment = std::true_type;
65 using propagate_on_container_swap = std::true_type; 58 using propagate_on_container_swap = std::true_type;
66 using is_always_equal = std::true_type; 59 using is_always_equal = std::true_type;
67 60
68public:
69 constexpr AlignmentAllocator() noexcept = default; 61 constexpr AlignmentAllocator() noexcept = default;
70 62
71 template <typename T2> 63 template <typename T2>
72 constexpr AlignmentAllocator(const AlignmentAllocator<T2, Align>&) noexcept {} 64 constexpr AlignmentAllocator(const AlignmentAllocator<T2, Align>&) noexcept {}
73 65
74 pointer address(reference r) noexcept { 66 T* allocate(size_type n) {
75 return std::addressof(r); 67 return static_cast<T*>(::operator new (n * sizeof(T), std::align_val_t{Align}));
76 }
77
78 const_pointer address(const_reference r) const noexcept {
79 return std::addressof(r);
80 }
81
82 pointer allocate(size_type n) {
83 return static_cast<pointer>(::operator new (n, std::align_val_t{Align}));
84 }
85
86 void deallocate(pointer p, size_type) {
87 ::operator delete (p, std::align_val_t{Align});
88 } 68 }
89 69
90 void construct(pointer p, const value_type& wert) { 70 void deallocate(T* p, size_type n) {
91 new (p) value_type(wert); 71 ::operator delete (p, n * sizeof(T), std::align_val_t{Align});
92 }
93
94 void destroy(pointer p) {
95 p->~value_type();
96 }
97
98 size_type max_size() const noexcept {
99 return size_type(-1) / sizeof(value_type);
100 } 72 }
101 73
102 template <typename T2> 74 template <typename T2>
103 struct rebind { 75 struct rebind {
104 using other = AlignmentAllocator<T2, Align>; 76 using other = AlignmentAllocator<T2, Align>;
105 }; 77 };
106
107 bool operator!=(const AlignmentAllocator<T, Align>& other) const noexcept {
108 return !(*this == other);
109 }
110
111 // Returns true if and only if storage allocated from *this
112 // can be deallocated from other, and vice versa.
113 // Always returns true for stateless allocators.
114 bool operator==(const AlignmentAllocator<T, Align>& other) const noexcept {
115 return true;
116 }
117}; 78};
118 79
119} // namespace Common 80} // namespace Common