1#ifndef STATIC_VECTOR_HH
2#define STATIC_VECTOR_HH
10#include <initializer_list>
31template<
typename T,
size_t N>
35 std::conditional_t<N <= std::numeric_limits<uint8_t >::max(), uint8_t,
36 std::conditional_t<N <= std::numeric_limits<uint16_t>::max(), uint16_t,
37 std::conditional_t<N <= std::numeric_limits<uint32_t>::max(), uint32_t,
56 assert(list.size() <= N);
58 sz = SizeType(list.size());
61 template<
typename Range>
63 for (
auto&& elem : range) {
64 push_back(std::forward<
decltype(elem)>(elem));
68 [[nodiscard]]
constexpr auto begin() noexcept {
return array.begin(); }
69 [[nodiscard]]
constexpr auto begin() const noexcept {
return array.begin(); }
70 [[nodiscard]]
constexpr auto end() noexcept {
return array.begin() + sz; }
71 [[nodiscard]]
constexpr auto end() const noexcept {
return array.begin() + sz; }
77 [[nodiscard]]
constexpr size_t size() const noexcept {
return sz; }
78 [[nodiscard]]
constexpr size_t max_size() const noexcept {
return array.max_size(); }
79 [[nodiscard]]
constexpr bool empty() const noexcept {
return sz == 0; }
81 [[nodiscard]]
constexpr T&
operator[](
size_t index)
noexcept {
return array[index]; }
82 [[nodiscard]]
constexpr const T&
operator[](
size_t index)
const noexcept {
return array[index]; }
83 [[nodiscard]]
constexpr T&
front() noexcept { assert(sz > 0);
return array[0]; }
84 [[nodiscard]]
constexpr const T&
front() const noexcept { assert(sz > 0);
return array[0]; }
85 [[nodiscard]]
constexpr T&
back() noexcept { assert(sz > 0);
return array[sz - 1]; }
86 [[nodiscard]]
constexpr const T&
back() const noexcept { assert(sz > 0);
return array[sz - 1]; }
87 [[nodiscard]]
constexpr T*
data() noexcept {
return array.data(); }
88 [[nodiscard]]
constexpr const T*
data() const noexcept {
return array.data(); }
90 constexpr void push_back(
const T& a) { assert(sz < N); array[sz++] = a; }
91 constexpr void push_back(T&& a) { assert(sz < N); array[sz++] = std::move(a); }
92 constexpr void pop_back() noexcept { assert(sz > 0); sz--; }
93 constexpr void clear() noexcept { sz = 0; }
95 operator std::span< T>() noexcept {
return {array.data(), sz}; }
96 operator std::span<const T>() const noexcept {
return {array.data(), sz}; }
99 std::array<T, N> array = {};
const value_type * const_iterator
constexpr auto rbegin() noexcept
constexpr T & operator[](size_t index) noexcept
constexpr size_t max_size() const noexcept
constexpr auto begin() const noexcept
ptrdiff_t difference_type
constexpr size_t size() const noexcept
constexpr void clear() noexcept
constexpr void pop_back() noexcept
constexpr static_vector(from_range_t, Range &&range)
constexpr T & front() noexcept
constexpr bool empty() const noexcept
constexpr static_vector(std::initializer_list< T > list)
std::reverse_iterator< iterator > reverse_iterator
constexpr static_vector()=default
constexpr void push_back(T &&a)
constexpr auto rend() const noexcept
constexpr auto rend() noexcept
constexpr T & back() noexcept
const value_type * const_pointer
constexpr const T & back() const noexcept
constexpr auto end() noexcept
constexpr T * data() noexcept
constexpr const T * data() const noexcept
constexpr auto begin() noexcept
constexpr auto end() const noexcept
constexpr auto rbegin() const noexcept
constexpr const T & front() const noexcept
const value_type & const_reference
constexpr const T & operator[](size_t index) const noexcept
std::reverse_iterator< const_iterator > const_reverse_iterator
constexpr void push_back(const T &a)
constexpr auto copy(InputRange &&range, OutputIter out)
constexpr from_range_t from_range