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)
noexcept {
39 contents = other.contents;
42 other.contents =
nullptr;
52 [[nodiscard]]
const T& GetBegin()
const {
56 [[nodiscard]] T& GetBegin() {
60 [[nodiscard]]
const T& GetEnd()
const {
61 return contents[size];
64 [[nodiscard]] T& GetEnd() {
65 return contents[size];
68 bool TryGet(T& outValue,
size_t index) {
77 size_t GetSize()
const {
81 Span<T> GetSubspan(
size_t firstIndex,
size_t count) {
82 GS_ASSERT_ENGINE_WITH_MESSAGE(count == 0 || firstIndex + count <= size,
"Array index is invalid.");
83 return Span<T>{ &contents[firstIndex], count };
86 T& operator[](
size_t index) {
87 GS_ASSERT_ENGINE_WITH_MESSAGE(index < size,
"Array index is invalid.");
88 return contents[index];
91 const T& operator[](
size_t index)
const {
92 GS_ASSERT_ENGINE_WITH_MESSAGE(index < size,
"Array index is invalid.");
93 return contents[index];
96 [[nodiscard]]
constexpr Iterator begin()
noexcept {
97 return Iterator(contents);
100 [[nodiscard]]
constexpr ConstIterator begin()
const noexcept {
101 return ConstIterator(contents);
104 [[nodiscard]]
constexpr Iterator end()
noexcept {
105 return Iterator(&contents[size]);
108 [[nodiscard]]
constexpr ConstIterator end()
const noexcept {
109 return ConstIterator(&contents[size - 1]);
112 [[nodiscard]]
constexpr ReverseIterator rbegin()
noexcept {
113 return ReverseIterator(&contents[size - 1]);
116 [[nodiscard]]
constexpr ConstReverseIterator rbegin()
const noexcept {
117 return ConstReverseIterator(&contents[size - 1]);
120 [[nodiscard]]
constexpr ReverseIterator rend()
noexcept {
121 return ReverseIterator(contents - 1);
124 [[nodiscard]]
constexpr ConstReverseIterator rend()
const noexcept {
125 return ConstReverseIterator(contents - 1);
128 [[nodiscard]]
constexpr ConstIterator cbegin()
const noexcept {
129 return ConstIterator(contents);
132 [[nodiscard]]
constexpr ConstIterator cend()
const noexcept {
133 return ConstIterator(&contents[size]);
136 [[nodiscard]]
constexpr ConstReverseIterator crbegin()
const noexcept {
137 return ConstReverseIterator(&contents[size - 1]);
140 [[nodiscard]]
constexpr ConstReverseIterator crend()
const noexcept {
141 return ConstReverseIterator(contents - 1);
145 T* contents =
nullptr;