35 using self = AStaticVector;
36 using super = AStaticVector;
37 using iterator = StoredType*;
38 using const_iterator =
const StoredType*;
39 using reference = StoredType&;
40 using const_reference =
const StoredType&;
41 using value = StoredType;
43 constexpr AStaticVector()
noexcept: mBegin(
reinterpret_cast<StoredType*
>(&mStorage)), mEnd(mBegin) {}
44 constexpr AStaticVector(
const AStaticVector& rhs): AStaticVector() {
45 insert(mBegin, rhs.begin(), rhs.end());
47 constexpr AStaticVector(AStaticVector&& rhs)
noexcept: AStaticVector() {
48 insert(mBegin, std::make_move_iterator(rhs.begin()), std::make_move_iterator(rhs.end()));
51 constexpr AStaticVector(std::initializer_list<StoredType> rhs)
noexcept: AStaticVector() {
52 insert(mBegin, std::make_move_iterator(rhs.begin()), std::make_move_iterator(rhs.end()));
54 template<
typename Iterator>
55 constexpr AStaticVector(Iterator begin, Iterator end)
noexcept: AStaticVector() {
56 for (
auto it = begin; it != end; ++it) {
60 constexpr ~AStaticVector() {
61 for (
auto& v : *
this) {
67 static constexpr size_t capacity()
noexcept {
71 AStaticVector& operator=(
const AStaticVector& rhs) {
76 insert(mBegin, rhs.begin(), rhs.end());
80 AStaticVector& operator=(AStaticVector&& rhs)
noexcept {
85 insert(mBegin, std::make_move_iterator(rhs.begin()), std::make_move_iterator(rhs.end()));
91 constexpr bool full()
const noexcept {
92 return size() >= MaxSize;
96 constexpr StoredType* data()
noexcept {
100 constexpr const StoredType* data()
const noexcept {
105 constexpr iterator begin()
noexcept {
109 constexpr const_iterator begin()
const noexcept {
114 constexpr iterator end()
noexcept {
119 constexpr const_iterator end()
const noexcept {
124 constexpr StoredType& front()
noexcept {
129 constexpr StoredType& back()
noexcept {
130 return *std::prev(end());
134 constexpr const StoredType& front()
const noexcept {
139 constexpr const StoredType& back()
const noexcept {
140 return *std::prev(end());
143 template<
typename... Args>
144 constexpr void emplace_back(Args&&... args)
noexcept {
145 AUI_ASSERTX(!full(),
"insufficient size in AStaticVector");
146 new (mEnd++) StoredType(std::forward<Args>(args)...);
150 constexpr void push_back(StoredType value)
noexcept {
151 AUI_ASSERTX(!full(),
"insufficient size in AStaticVector");
152 new (mEnd++) StoredType(std::move(value));
155 constexpr void push_front(StoredType value)
noexcept {
156 AUI_ASSERTX(!full(),
"insufficient size in AStaticVector");
157 insert(begin(), std::move(value));
160 constexpr void pop_back()
noexcept {
162 erase(std::prev(end()));
164 constexpr void pop_front()
noexcept {
170 constexpr StoredType& operator[](std::size_t index)
noexcept {
172 return *(data() + index);
176 constexpr StoredType& operator[](std::size_t index)
const noexcept {
177 return const_cast<AStaticVector*
>(
this)->
operator[](index);
181 constexpr bool empty()
const noexcept {
182 return begin() == end();
185 constexpr void clear()
noexcept {
186 for (
auto& v : *
this) {
193 constexpr std::size_t size()
const noexcept {
194 return mEnd - mBegin;
197 template<
typename OtherIterator>
198 constexpr iterator insert(iterator at, OtherIterator begin, OtherIterator end) {
199 AUI_ASSERT_MY_ITERATOR(at);
200 auto distance = std::distance(begin, end);
201 AUI_ASSERTX(size() + distance <= MaxSize,
"out of bounds");
203 return aui::container::vector_impl::insert_no_growth(mEnd, at, begin, end);
206 constexpr iterator insert(iterator at, StoredType value) {
207 AUI_ASSERT_MY_ITERATOR(at);
208 return insert(at, std::make_move_iterator(&value), std::make_move_iterator(&value + 1));
211 constexpr iterator erase(iterator at) {
212 return erase(at, std::next(at));
215 constexpr iterator erase(iterator begin, iterator end) {
216 AUI_ASSERT_MY_ITERATOR(begin);
217 AUI_ASSERT_MY_ITERATOR(end);
219 return aui::container::vector_impl::erase(mBegin, mEnd, begin, end);
222 void reserve(std::size_t) {
235 template<
typename OtherContainer>
247 template<
typename OtherContainer>
249 return insertAll(super::end(), std::forward<OtherContainer>(c));
260 template<
typename OtherContainer>
261 iterator
insertAll(iterator at,
const OtherContainer& c)
noexcept {
262 return super::insert(at, c.begin(), c.end());
273 template<
typename OtherContainer>
274 iterator
insertAll(iterator at, OtherContainer&& c)
noexcept {
275 return super::insert(at, std::make_move_iterator(c.begin()), std::make_move_iterator(c.end()));
301 template<
typename OtherContainer>
310 bool contains(
const StoredType& value)
const noexcept {
315 std::size_t sizeInBytes() const noexcept {
316 return super::size() *
sizeof(StoredType);
320 StoredType& at(std::size_t index) {
321 if (index >= super::size()) {
322 aui::impl::outOfBoundsException();
324 return super::operator[](index);
328 const StoredType& at(std::size_t index)
const {
329 if (index >= super::size()) {
330 aui::impl::outOfBoundsException();
332 return super::operator[](index);
343 super::push_back(rhs);
354 super::push_back(std::forward<StoredType>(rhs));
363 template<
typename OtherContainer, std::enable_if_t<!std::is_convertible_v<OtherContainer, StoredType>,
bool> = true>
375 template<
typename OtherContainer, std::enable_if_t<!std::is_convertible_v<OtherContainer, StoredType>,
bool> = true>
378 insertAll(std::forward<OtherContainer>(c));
392 AUI_ASSERTX(!super::empty(),
"empty container could not have the first element");
393 return super::front();
403 const StoredType&
first() const noexcept
405 AUI_ASSERTX(!super::empty(),
"empty container could not have the first element");
406 return super::front();
418 AUI_ASSERTX(!super::empty(),
"empty container could not have the last element");
419 return super::back();
429 const StoredType&
last() const noexcept
431 AUI_ASSERTX(!super::empty(),
"empty container could not have the last element");
432 return super::back();
446 void sort() noexcept {
447 std::sort(super::begin(), super::end());
450 template<
typename Comparator>
451 void sort(Comparator&& comparator)
noexcept {
452 std::sort(super::begin(), super::end(), std::forward<Comparator>(comparator));
472 template<
typename Predicate>
475 super::erase(std::remove_if(super::begin(), super::end(), std::forward<Predicate>(predicate)), super::end());
488 template<aui::incrementable Iterator, aui::invocable<decltype(*std::declval<Iterator>())> UnaryOperation>
490 AVector<
decltype(transformer(range.first()))> result;
491 result.reserve(range.size());
492 std::transform(range.begin(), range.end(), std::back_inserter(result), std::forward<UnaryOperation>(transformer));
496 template<aui::invocable<const StoredType&> UnaryOperation>
499 result.reserve(super::size());
500 std::transform(super::begin(), super::end(), std::back_inserter(result), std::forward<UnaryOperation>(transformer));
504 template<aui::invocable<const StoredType&> UnaryOperation>
506 auto toMap(UnaryOperation&& transformer)
const -> AMap<decltype(transformer(std::declval<StoredType>()).
first),
507 decltype(transformer(std::declval<StoredType>()).second)> {
511 template<aui::invocable<StoredType&> UnaryOperation>
513 auto toMap(UnaryOperation&& transformer) -> AMap<decltype(transformer(std::declval<StoredType>()).
first),
514 decltype(transformer(std::declval<StoredType>()).second)> {
518 template<aui::predicate<const StoredType&> Predicate>
519 self filter(Predicate&& predicate) {
521 result.reserve(super::size());
522 for (
const auto& element : *
this) {
523 if (predicate(element)) {
524 result.push_back(element);
531 operator std::span<StoredType>() {
532 return std::span(data(), size());
536 operator std::span<const StoredType>()
const {
537 return std::span(data(), size());
543 std::aligned_storage_t<
sizeof(StoredType) * MaxSize,
alignof(StoredType)> mStorage;