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) {}
81 [[nodiscard]]
constexpr bool empty()
const noexcept
83 return _begin == _end;
86 [[nodisardd]]
constexpr size_type size()
const noexcept
88 return static_cast<size_type>(_end - _begin);
91 [[nodiscard]]
constexpr size_type max_size()
const noexcept
96 [[nodiscard]]
constexpr size_type capacity()
const noexcept
98 return static_cast<size_type>(_bound - _begin);
103 auto *ptr = _begin + pos;
111 [[nodiscard]]
constexpr const_reference at(
size_type pos)
const
113 auto *ptr = _begin + pos;
123 auto *ptr = _begin + pos;
128 [[nodiscard]]
constexpr const_reference operator[](
size_type pos)
const noexcept
130 auto *ptr = _begin + pos;
135 [[nodiscard]]
constexpr reference front()
noexcept
141 [[nodiscard]]
constexpr const_reference front()
const noexcept
147 [[nodiscard]]
constexpr reference back()
noexcept
153 [[nodiscard]]
constexpr const_reference back()
const noexcept
159 [[nodiscard]]
constexpr pointer data()
noexcept
164 [[nodiscard]]
constexpr const_pointer data()
const noexcept
169 [[nodiscard]]
constexpr iterator begin()
noexcept
174 [[nodiscard]]
constexpr const_iterator begin()
const noexcept
179 [[nodiscard]]
constexpr const_iterator cbegin()
const noexcept
184 [[nodiscard]]
constexpr iterator end()
noexcept
189 [[nodiscard]]
constexpr const_iterator end()
const noexcept
194 [[nodiscard]]
constexpr const_iterator cend()
const noexcept
200 constexpr void resize(
size_type new_size)
202 return _resize(new_size);
205 constexpr void resize(
size_type new_size, value_type
const &value)
207 return _resize(new_size, value);
210 constexpr void clear()
215 constexpr reference emplace_back(
auto &&...args)
218 auto tmp = std::construct_at(_end, tt_forward(args)...);
223 constexpr void push_back(value_type
const &value)
228 constexpr void push_back(value_type &&value)
233 constexpr void pop_back()
235 secure_destroy_at(back());
239 constexpr iterator emplace(const_iterator pos,
auto &&...args)
245 hilet first = _begin + index;
246 if (first != n_first) {
252 constexpr iterator insert(const_iterator pos, value_type
const &value)
254 return emplace(pos, value);
257 constexpr iterator insert(const_iterator pos, value_type &&value)
262 constexpr void reserve(
size_type new_capacity)
264 if (new_capacity <= capacity()) {
268 hilet tmp = allocate(new_capacity);
270 secure_unitialized_move(_begin, _end, _tmp);
272 _bound = tmp + new_capacity;
275 deallocate(tmp, new_capacity);
280 constexpr void shrink_to_fit()
283 if (_begin !=
nullptr) {
284 deallocate(_begin, capacity());
285 _begin = _end = _capacity =
nullptr;
289 hilet new_capacity = size();
290 hilet tmp = allocate(new_capacity);
292 secure_unitialized_move(_begin, _end, _tmp);
294 _bound = tmp + new_capacity;
297 deallocate(tmp, new_capacity);
308 [[nodiscard]]
constexpr bool full()
const noexcept
310 return _end == _bound;
321 constexpr void grow(
size_t count)
const noexcept
323 if (_end + count <= _bound) {
327 ttlet minimum_new_capacity = size() + count;
330 auto new_capacity = capacity();
331 new_capacity += new_capacity >> 1;
333 if (new_capacity < minimum_new_capacity) {
334 reserve(minimum_new_capacity);
336 reserve(new_capacity);
340 template<
typename... Args>
341 constexpr void _resize(
size_t new_size, Args
const &... args)
345 hilet new_end = _begin + new_size;
347 if (new_end > _end) {
351 }
else (new_end < _end) {
#define hi_assert(expression,...)
Assert if expression is true.
Definition assert.hpp:184
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:156