4#include "../Containers/Algorithms/AlgorithmFind.h"
5#include "../Containers/Vector.h"
10template <
typename T,
int N>
11struct SC_COMPILER_EXPORT ArrayVTable :
public ObjectVTable<T>
13 static constexpr bool IsArray =
true;
15 T* data() {
return items; }
16 const T* data()
const {
return items; }
18 T* getInlineData() {
return items; }
19 uint32_t getInlineCapacity() {
return header.capacityBytes; }
21 static constexpr bool isInline() {
return true; }
23 ArrayVTable(uint32_t capacity = 0, SegmentAllocator allocator = SegmentAllocator::Global)
24 : header(capacity, allocator)
49template <
typename T,
int N>
50struct SC_COMPILER_EXPORT
Array :
public Segment<detail::ArrayVTable<T, N>>
76 [[nodiscard]]
bool contains(
const U& value,
size_t* index =
nullptr)
const
78 return Algorithms::contains(*
this, value, index);
83 template <
typename Lambda>
84 [[nodiscard]]
bool find(Lambda&& lambda,
size_t* index =
nullptr)
const
86 return Algorithms::findIf(Parent::begin(), Parent::end(),
move(lambda), index) != Parent::end();
91 template <
typename Lambda>
94 T* itBeg = Parent::begin();
95 T* itEnd = Parent::end();
96 T* it = Algorithms::removeIf(itBeg, itEnd, forward<Lambda>(criteria));
98 const size_t numBytes =
static_cast<size_t>(itEnd - it) *
sizeof(T);
99 const size_t offBytes =
static_cast<size_t>(it - itBeg) *
sizeof(T);
100 detail::VectorVTable<T>::destruct(Parent::getData(), offBytes, numBytes);
101 Parent::header.sizeBytes -=
static_cast<decltype(Parent::header.sizeBytes)
>(numBytes);
107 template <
typename U>
108 [[nodiscard]]
bool remove(
const U& value)
110 return removeAll([&](
auto& item) {
return item == value; });
#define SC_ASSERT_RELEASE(e)
Assert expression e to be true.
Definition Assert.h:46
constexpr T && move(T &value)
Converts an lvalue to an rvalue reference.
Definition Compiler.h:264
unsigned int uint32_t
Platform independent (4) bytes unsigned int.
Definition PrimitiveTypes.h:38
A contiguous sequence of elements kept inside its inline storage.
Definition Array.h:51
bool removeAll(Lambda &&criteria)
Removes all items matching criteria given by Lambda.
Definition Array.h:92
bool remove(const U &value)
Removes all values equal to value
Definition Array.h:108
bool find(Lambda &&lambda, size_t *index=nullptr) const
Finds the first item in array matching criteria given by the lambda.
Definition Array.h:84
bool contains(const U &value, size_t *index=nullptr) const
Check if the current array contains a given value.
Definition Array.h:76
A slice of contiguous memory, prefixed by and header containing size and capacity.
Definition Segment.h:113
View over a contiguous sequence of items (pointer + size in elements).
Definition Span.h:29