22 using difference_type = ssize_t;
37 hi_assert_not_null(ptr);
42 hi_assert_not_null(ptr);
47 [[nodiscard]] value_type &operator*()
noexcept
49 return *std::launder(ptr);
51 [[nodiscard]] value_type
const &operator*()
const noexcept
53 return *std::launder(ptr);
55 [[nodiscard]] value_type *operator->()
noexcept
57 return std::launder(ptr);
59 [[nodiscard]] value_type
const *operator->()
const noexcept
61 return std::launder(ptr);
63 [[nodiscard]] value_type &operator[](
std::size_t i)
noexcept
65 return *std::launder(ptr + i);
67 [[nodiscard]] value_type
const &operator[](
std::size_t i)
const noexcept
69 return *std::launder(ptr + i);
108 return lhs.ptr == rhs.ptr;
113 return lhs.ptr <=> rhs.ptr;
131 return lhs.ptr - rhs.ptr;
138 using value_type = T;
148 vector_span() noexcept : _begin(
nullptr), _end(
nullptr), _max(
nullptr) {}
150 vector_span(value_type *buffer, ssize_t nr_elements) noexcept : _begin(buffer), _end(buffer), _max(buffer + nr_elements)
152 hi_axiom(nr_elements >= 0);
155 vector_span(std::span<value_type> span) noexcept : _begin(span.data()), _end(span.data()), _max(span.data() + span.size()) {}
163 [[nodiscard]]
iterator begin()
noexcept
176 [[nodiscard]]
iterator end()
noexcept
194 [[nodiscard]] value_type &operator[](
std::size_t i)
noexcept
196 hi_assert_bounds(i, *
this);
197 return *std::launder(_begin + i);
199 [[nodiscard]] value_type
const &operator[](
std::size_t i)
const noexcept
201 hi_assert_bounds(i, *
this);
202 return *std::launder(_begin + i);
205 value_type &front()
noexcept
207 hi_axiom(_end != _begin);
208 return *std::launder(_begin);
210 value_type
const &front()
const noexcept
212 hi_axiom(_end != _begin);
213 return *std::launder(_begin);
215 value_type &back()
noexcept
217 hi_axiom(_end != _begin);
218 return *std::launder(_end - 1);
220 value_type
const &back()
const noexcept
222 hi_axiom(_end != _begin);
223 return *std::launder(_end - 1);
226 [[nodiscard]]
bool empty()
const noexcept
228 return _begin == _end;
231 [[nodiscard]]
bool full()
const noexcept
236 void clear()
noexcept
238 for (
auto i = _begin; i != _end; ++i) {
239 std::destroy_at(std::launder(i));
244 void push_back(value_type
const &rhs)
noexcept
246 hi_axiom(_end != _max);
248 [[maybe_unused]] value_type *ptr =
new (_end) value_type(rhs);
252 void push_back(value_type &&rhs)
noexcept
254 hi_axiom(_end != _max);
256 [[maybe_unused]] value_type *ptr =
new (_end) value_type(
std::move(rhs));
260 template<
typename... Args>
261 void emplace_back(Args &&...args)
noexcept
263 hi_axiom(_end != _max);
264 std::construct_at(_end++, std::forward<Args>(args)...);
267 void pop_back()
noexcept
269 hi_axiom(_end != _begin);
271 std::destroy_at(std::launder(_end));