26 , storageEnd(storage.data() +
CAPACITY)
32 [[nodiscard]]
size_t capacity()
const {
return storageEnd - storage.data(); }
33 [[nodiscard]]
size_t spareFront()
const {
return useBegin - storage.data(); }
34 [[nodiscard]]
size_t spareBack()
const {
return storageEnd - useEnd; }
35 [[nodiscard]]
size_t size()
const {
return useEnd - useBegin; }
36 [[nodiscard]]
bool empty()
const {
return useEnd == useBegin; }
40 [[nodiscard]] T&
front() {
return *useBegin; }
41 [[nodiscard]]
const T&
front()
const {
return *useBegin; }
43 [[nodiscard]] T*
begin() {
return useBegin; }
44 [[nodiscard]]
const T*
begin()
const {
return useBegin; }
45 [[nodiscard]] T*
end() {
return useEnd; }
46 [[nodiscard]]
const T*
end()
const {
return useEnd; }
55 void insert(
const T&
t, std::invocable<T&>
auto setSentinel, std::equivalence_relation<T, T>
auto less)
58 assert(less(
t, *useEnd));
61 while (!less(
t, *it)) ++it;
63 if ((it - useBegin) <= (useEnd - it)) {
64 if (useBegin != storage.data()) [[likely]] {
66 }
else if (useEnd != storageEnd) {
72 if (useEnd != storageEnd) [[likely]] {
74 }
else if (useBegin != storage.data()) {
90 bool remove(std::predicate<T>
auto p)
92 T* it = std::find_if(useBegin, useEnd, p);
93 if (it == useEnd)
return false;
95 if ((it - useBegin) < (useEnd - it - 1)) [[unlikely]] {
97 std::copy_backward(useBegin - 1, it, it + 1);
99 std::copy(it + 1, useEnd, it);
108 useEnd = std::remove_if(useBegin, useEnd, p);
112 void insertFront(T* it,
const T&
t)
115 std::copy(useBegin + 1, it, useBegin);
119 void insertBack(T* it,
const T&
t)
122 std::copy_backward(it, useEnd -1, useEnd);
125 void insertRealloc(T* it,
const T&
t)
127 size_t oldSize = storageEnd - storage.data();
128 size_t newSize = oldSize * 2;
130 MemBuffer<T> newStorage(newSize + 1);
132 std::copy(useBegin, it, newUseBegin);
133 *(newUseBegin + (it - useBegin)) =
t;
134 std::copy(it, useEnd, newUseBegin + (it - useBegin) + 1);
136 storage = std::move(newStorage);
137 storageEnd = storage.data() + newSize;
138 useBegin = newUseBegin;
139 useEnd = useBegin + oldSize + 1;
144 MemBuffer<T> storage;