21 Span(T* ptr,
size_t size) :
25 Span(
const Span& other) : size(other.size), contents(other.contents) {}
27 Span(Span&& other) noexcept : size(other.size), contents(other.contents) {
29 other.contents =
nullptr;
32 Span& operator=(
const Span& other) {
34 contents = other.contents;
37 Span& operator=(Span&& other) {
39 contents = other.contents;
42 other.contents =
nullptr;
50 [[nodiscard]]
const T& GetBegin()
const {
54 [[nodiscard]] T& GetBegin() {
58 [[nodiscard]]
const T& GetEnd()
const {
59 return contents[size];
62 [[nodiscard]] T& GetEnd() {
63 return contents[size];
66 bool TryGet(T& outValue,
size_t index) {
75 size_t GetSize()
const {
79 Span<T> GetSubspan(
size_t firstIndex,
size_t count) {
80 GS_ASSERT_ENGINE_WITH_MESSAGE(count == 0 || firstIndex + count <= size,
"Array index is invalid.");
81 return Span<T>{ &contents[firstIndex], count };
84 T& operator[](
size_t index) {
85 GS_ASSERT_ENGINE_WITH_MESSAGE(index < size,
"Array index is invalid.");
86 return contents[index];
89 const T& operator[](
size_t index)
const {
90 GS_ASSERT_ENGINE_WITH_MESSAGE(index < size,
"Array index is invalid.");
91 return contents[index];
94 [[nodiscard]]
constexpr Iterator begin()
noexcept {
95 return Iterator(contents);
98 [[nodiscard]]
constexpr ConstIterator begin()
const noexcept {
99 return ConstIterator(contents);
102 [[nodiscard]]
constexpr Iterator end()
noexcept {
103 return Iterator(&contents[size]);
106 [[nodiscard]]
constexpr ConstIterator end()
const noexcept {
107 return ConstIterator(&contents[size - 1]);
110 [[nodiscard]]
constexpr ReverseIterator rbegin()
noexcept {
111 return ReverseIterator(&contents[size - 1]);
114 [[nodiscard]]
constexpr ConstReverseIterator rbegin()
const noexcept {
115 return ConstReverseIterator(&contents[size - 1]);
118 [[nodiscard]]
constexpr ReverseIterator rend()
noexcept {
119 return ReverseIterator(contents - 1);
122 [[nodiscard]]
constexpr ConstReverseIterator rend()
const noexcept {
123 return ConstReverseIterator(contents - 1);
126 [[nodiscard]]
constexpr ConstIterator cbegin()
const noexcept {
127 return ConstIterator(contents);
130 [[nodiscard]]
constexpr ConstIterator cend()
const noexcept {
131 return ConstIterator(&contents[size]);
134 [[nodiscard]]
constexpr ConstReverseIterator crbegin()
const noexcept {
135 return ConstReverseIterator(&contents[size - 1]);
138 [[nodiscard]]
constexpr ConstReverseIterator crend()
const noexcept {
139 return ConstReverseIterator(contents - 1);
143 T* contents =
nullptr;