4#include "../Containers/Algorithms/AlgorithmFind.h"
5#include "../Containers/Vector.h"
6#include "ContainersExport.h"
11template <
typename T,
int N>
12struct SC_CONTAINERS_EXPORT ArrayVTable :
public ObjectVTable<T>
14 static constexpr bool IsArray =
true;
16 T* data() {
return items; }
17 const T* data()
const {
return items; }
19 T* getInlineData() {
return items; }
20 uint32_t getInlineCapacity() {
return header.capacityBytes; }
22 static constexpr bool isInline() {
return true; }
24 ArrayVTable(uint32_t capacity = 0, SegmentAllocator allocator = SegmentAllocator::Global)
25 : header(capacity, allocator)
50template <
typename T,
int N>
51struct SC_CONTAINERS_EXPORT
Array :
public Segment<detail::ArrayVTable<T, N>>
56 Array(std::initializer_list<T> list) :
Array() { SC_CONTAINERS_ASSERT_RELEASE(Parent::template assign<T>({list.begin(), list.size()})); }
57 Array(
const Array& other) :
Array() { SC_CONTAINERS_ASSERT_RELEASE(Parent::append(other.toSpanConst())); }
58 Array(
Array&& other) :
Array() { SC_CONTAINERS_ASSERT_RELEASE(Parent::appendMove(move(other))); }
59 Array& operator=(
const Array& other) { SC_CONTAINERS_ASSERT_RELEASE(Parent::assign(other.toSpanConst()));
return *
this; }
60 Array& operator=(
Array&& other) { SC_CONTAINERS_ASSERT_RELEASE(Parent::assignMove(move(other)));
return *
this; }
62 Array(
const Array<T, M>& other) :
Array() { SC_CONTAINERS_ASSERT_RELEASE(Parent::assign(other.toSpanConst()));}
64 Array(
Array<T, M>&& other) :
Array() { SC_CONTAINERS_ASSERT_RELEASE(Parent::assignMove(move(other))); }
66 Array& operator=(
const Array<T, M>& other) { SC_CONTAINERS_ASSERT_RELEASE(Parent::assign(other.toSpanConst()));
return *
this; }
68 Array& operator=(
Array<T, M>&& other) { SC_CONTAINERS_ASSERT_RELEASE(Parent::assignMove(move(other)));
return *
this; }
69 Array(Span<const T> span) :
Array() { SC_CONTAINERS_ASSERT_RELEASE(Parent::assign(span)); }
71 Array(Span<const U> span) :
Array() { SC_CONTAINERS_ASSERT_RELEASE(Parent::assign(span)); }
77 [[nodiscard]]
bool contains(
const U& value,
size_t* index =
nullptr)
const
79 return Algorithms::contains(*
this, value, index);
84 template <
typename Lambda>
85 [[nodiscard]]
bool find(Lambda&& lambda,
size_t* index =
nullptr)
const
87 return Algorithms::findIf(Parent::begin(), Parent::end(), move(lambda), index) != Parent::end();
92 template <
typename Lambda>
95 T* itBeg = Parent::begin();
96 T* itEnd = Parent::end();
97 T* it = Algorithms::removeIf(itBeg, itEnd, forward<Lambda>(criteria));
99 const size_t numBytes =
static_cast<size_t>(itEnd - it) *
sizeof(T);
100 const size_t offBytes =
static_cast<size_t>(it - itBeg) *
sizeof(T);
101 detail::VectorVTable<T>::destruct(Parent::getData(), offBytes, numBytes);
102 Parent::header.sizeBytes -=
static_cast<decltype(Parent::header.sizeBytes)
>(numBytes);
108 template <
typename U>
109 [[nodiscard]]
bool remove(
const U& value)
111 return removeAll([&](
auto& item) {
return item == value; });
A contiguous sequence of elements kept inside its inline storage.
Definition Array.h:52
bool removeAll(Lambda &&criteria)
Removes all items matching criteria given by Lambda.
Definition Array.h:93
bool remove(const U &value)
Removes all values equal to value
Definition Array.h:109
bool find(Lambda &&lambda, size_t *index=nullptr) const
Finds the first item in array matching criteria given by the lambda.
Definition Array.h:85
bool contains(const U &value, size_t *index=nullptr) const
Check if the current array contains a given value.
Definition Array.h:77
A slice of contiguous memory, prefixed by and header containing size and capacity.
Definition Segment.h:168