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>>
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; });
#define SC_ASSERT_RELEASE(e)
Assert expression e to be true.
Definition Assert.h:48
constexpr T && move(T &value)
Converts an lvalue to an rvalue reference.
Definition Compiler.h:273
unsigned int uint32_t
Platform independent (4) bytes unsigned int.
Definition PrimitiveTypes.h:29
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:114
View over a contiguous sequence of items (pointer + size in elements).
Definition Span.h:29