56 using allocator_type = Allocator;
60 using const_reference = value_type
const &;
63 using iterator = value_type *;
64 using const_iterator = value_type
const *;
70 constexpr secure_vector() noexcept : _begin(
nullptr), _end(
nullptr), _bound(
nullptr) {}
76 hi_axiom(_begin =
nullptr);
79 [[nodiscard]]
constexpr bool empty()
const noexcept
81 return _begin == _end;
84 [[nodisardd]]
constexpr size_type size()
const noexcept
86 return static_cast<size_type>(_end - _begin);
89 [[nodiscard]]
constexpr size_type max_size()
const noexcept
94 [[nodiscard]]
constexpr size_type capacity()
const noexcept
96 return static_cast<size_type>(_bound - _begin);
101 auto *ptr = _begin + pos;
109 [[nodiscard]]
constexpr const_reference at(
size_type pos)
const
111 auto *ptr = _begin + pos;
121 auto *ptr = _begin + pos;
122 hi_axiom(ptr < _end);
126 [[nodiscard]]
constexpr const_reference operator[](
size_type pos)
const noexcept
128 auto *ptr = _begin + pos;
129 hi_axiom(ptr < _end);
133 [[nodiscard]]
constexpr reference front()
noexcept
135 hi_axiom(not empty());
139 [[nodiscard]]
constexpr const_reference front()
const noexcept
141 hi_axiom(not empty());
145 [[nodiscard]]
constexpr reference back()
noexcept
147 hi_axiom(not empty());
151 [[nodiscard]]
constexpr const_reference back()
const noexcept
153 hi_axiom(not empty());
157 [[nodiscard]]
constexpr pointer data()
noexcept
162 [[nodiscard]]
constexpr const_pointer data()
const noexcept
167 [[nodiscard]]
constexpr iterator begin()
noexcept
172 [[nodiscard]]
constexpr const_iterator begin()
const noexcept
177 [[nodiscard]]
constexpr const_iterator cbegin()
const noexcept
182 [[nodiscard]]
constexpr iterator end()
noexcept
187 [[nodiscard]]
constexpr const_iterator end()
const noexcept
192 [[nodiscard]]
constexpr const_iterator cend()
const noexcept
198 constexpr void resize(
size_type new_size)
200 return _resize(new_size);
203 constexpr void resize(
size_type new_size, value_type
const &value)
205 return _resize(new_size, value);
208 constexpr void clear()
213 constexpr reference emplace_back(
auto &&...args)
216 auto tmp = std::construct_at(_end, tt_forward(args)...);
221 constexpr void push_back(value_type
const &value)
226 constexpr void push_back(value_type &&value)
231 constexpr void pop_back()
233 secure_destroy_at(back());
237 constexpr iterator emplace(const_iterator pos,
auto &&...args)
243 hilet first = _begin + index;
244 if (first != n_first) {
250 constexpr iterator insert(const_iterator pos, value_type
const &value)
252 return emplace(pos, value);
255 constexpr iterator insert(const_iterator pos, value_type &&value)
260 constexpr void reserve(
size_type new_capacity)
262 if (new_capacity <= capacity()) {
266 hilet tmp = allocate(new_capacity);
268 secure_unitialized_move(_begin, _end, _tmp);
270 _bound = tmp + new_capacity;
273 deallocate(tmp, new_capacity);
278 constexpr void shrink_to_fit()
281 if (_begin !=
nullptr) {
282 deallocate(_begin, capacity());
283 _begin = _end = _capacity =
nullptr;
287 hilet new_capacity = size();
288 hilet tmp = allocate(new_capacity);
290 secure_unitialized_move(_begin, _end, _tmp);
292 _bound = tmp + new_capacity;
295 deallocate(tmp, new_capacity);
306 [[nodiscard]]
constexpr bool full()
const noexcept
308 return _end == _bound;
319 constexpr void grow(
size_t count)
const noexcept
321 if (_end + count <= _bound) {
325 ttlet minimum_new_capacity = size() + count;
328 auto new_capacity = capacity();
329 new_capacity += new_capacity >> 1;
331 if (new_capacity < minimum_new_capacity) {
332 reserve(minimum_new_capacity);
334 reserve(new_capacity);
338 template<
typename... Args>
339 constexpr void _resize(
size_t new_size, Args
const &... args)
343 hilet new_end = _begin + new_size;
345 if (new_end > _end) {
349 }
else (new_end < _end) {
void secure_destroy(It first, It last)
Securely destroy objects.
Definition security.hpp:68
void construct(It first, It last, Args const &...args)
Construct a set of objects.
Definition memory.hpp:153