38class AVector:
public std::vector<StoredType, Allocator>
41 using super = std::vector<StoredType, Allocator>;
42 using self = AVector<StoredType, Allocator>;
46 using iterator =
typename super::iterator;
48 template<
typename Iterator>
51 explicit AVector(std::vector<StoredType, Allocator>&& rhs)
noexcept: super(std::move(rhs)) {}
60 template<
typename OtherContainer>
61 iterator
insertAll(
const OtherContainer& c)
noexcept {
72 template<
typename OtherContainer>
74 return insertAll(super::end(), std::forward<OtherContainer>(c));
85 template<
typename OtherContainer>
86 iterator
insertAll(iterator at,
const OtherContainer& c)
noexcept {
87 return super::insert(at, c.begin(), c.end());
98 template<
typename OtherContainer>
99 iterator
insertAll(iterator at, OtherContainer&& c)
noexcept {
100 return super::insert(at, std::make_move_iterator(c.begin()), std::make_move_iterator(c.end()));
119 template<
typename T, aui::mapper<const StoredType&, const T&> Projection>
120 void removeAll(
const T& item, Projection projection)
noexcept
139 template<
typename OtherContainer>
148 bool contains(
const StoredType& value)
const noexcept {
153 std::size_t sizeInBytes() const noexcept {
154 return super::size() *
sizeof(StoredType);
158 StoredType& at(std::size_t index) {
159 if (index >= super::size()) {
160 aui::impl::outOfBoundsException();
162 return super::operator[](index);
166 const StoredType& at(std::size_t index)
const {
167 if (index >= super::size()) {
168 aui::impl::outOfBoundsException();
170 return super::operator[](index);
181 super::push_back(rhs);
192 super::push_back(std::move(rhs));
201 template<
typename OtherContainer, std::enable_if_t<!std::is_convertible_v<OtherContainer, StoredType>,
bool> = true>
213 template<
typename OtherContainer, std::enable_if_t<!std::is_convertible_v<OtherContainer, StoredType>,
bool> = true>
216 insertAll(std::forward<OtherContainer>(c));
231 AUI_ASSERTX(!super::empty(),
"empty container could not have the first element");
232 return super::front();
243 const StoredType&
first() const noexcept
245 AUI_ASSERTX(!super::empty(),
"empty container could not have the first element");
246 return super::front();
259 AUI_ASSERTX(!super::empty(),
"empty container could not have the last element");
260 return super::back();
271 const StoredType&
last() const noexcept
273 AUI_ASSERTX(!super::empty(),
"empty container could not have the last element");
274 return super::back();
290 std::sort(super::begin(), super::end());
294 template<
typename Comparator>
295 AVector<StoredType>& sort(Comparator&& comparator)
noexcept {
296 std::sort(super::begin(), super::end(), std::forward<Comparator>(comparator));
305 template<aui::predicate<StoredType> Predicate>
307 StoredType*
findIf(Predicate&& predicate)
noexcept
309 if (
auto i = std::find_if(super::begin(), super::end(), std::forward<Predicate>(predicate)); i != super::end()) {
333 template<aui::predicate<StoredType> Predicate>
336 super::erase(std::remove_if(super::begin(), super::end(), std::forward<Predicate>(predicate)), super::end());
343 template<aui::predicate<StoredType> Predicate>
346 auto i = std::find_if(super::begin(), super::end(), std::forward<Predicate>(predicate));
347 if (i == super::end()) {
353 template<aui::mapper<std::
size_t, StoredType> Callable>
358 for (
size_t i = 0; i < size; ++i) {
365 ASet<StoredType> toSet() const noexcept {
366 return ASet<StoredType>(super::begin(), super::end());
375 template<aui::incrementable Iterator, aui::invocable<decltype(*std::declval<Iterator>())> UnaryOperation>
378 AVector<
decltype(transformer(range.first()))> result;
379 result.reserve(range.size());
380 std::transform(range.begin(), range.end(), std::back_inserter(result), std::forward<UnaryOperation>(transformer));
384 template<aui::invocable<StoredType&> UnaryOperation>
388 result.reserve(super::size());
389 std::transform(super::begin(), super::end(), std::back_inserter(result), std::forward<UnaryOperation>(transformer));
393 template<aui::invocable<const StoredType&> UnaryOperation>
395 auto map(UnaryOperation&& transformer)
const -> AVector<decltype(transformer(std::declval<StoredType>()))> {
396 AVector<decltype(transformer(std::declval<StoredType>()))> result;
397 result.reserve(super::size());
398 std::transform(super::begin(), super::end(), std::back_inserter(result), std::forward<UnaryOperation>(transformer));
402 template<aui::invocable<const StoredType&> UnaryOperation>
404 auto toMap(UnaryOperation&& transformer)
const -> AMap<decltype(transformer(std::declval<StoredType>()).
first),
405 decltype(transformer(std::declval<StoredType>()).second)> {
409 template<aui::invocable<StoredType&> UnaryOperation>
411 auto toMap(UnaryOperation&& transformer) -> AMap<decltype(transformer(std::declval<StoredType>()).
first),
412 decltype(transformer(std::declval<StoredType>()).second)> {
416 template<aui::predicate<const StoredType&> Predicate>
418 self filter(Predicate&& predicate) {
420 result.reserve(super::size());
421 for (
const auto& element : *
this) {
422 if (predicate(element)) {
423 result.push_back(element);