// #pragma once // #include // #include // #include "commons/commons_base.h" // #include "commons/commons_mem.h" // template // [[nodiscard]] // auto span::operator[](uint64_t i) -> T& // { // DASSERT(i < size); // return data[i]; // } // template // [[nodiscard]] // auto span::operator[](uint64_t i) const -> const T& // { // DASSERT(i < size); // return data[i]; // } // template // [[nodiscard]] // INLINE auto Span_IsEmpty(span self) -> bool // { // return self.size == 0; // } // template // [[nodiscard]] // INLINE auto Span_CStr(span self) -> const char* // requires(sizeof(T) == 1) // { // DASSERT(*(self.data + self.size) == 0); // return (const char*)self.data; // } // template // [[nodiscard]] // INLINE auto Span_SizeBytes(span self) -> uint64_t // { // return self.size * sizeof(T); // } // template // INLINE auto Span_Resize(span self, uint64_t newSize) -> span // { // self.size = newSize; // return self; // } // template // [[nodiscard]] // INLINE auto Span_SubSpan(span self, uint64_t from) -> span // { // const uint64_t retSize = self.size - from; // DASSERT(retSize >= 0); // return { self.data + from, retSize }; // } // template // [[nodiscard]] // INLINE auto Span_SubSpan(span self, uint64_t from, uint64_t size) -> span // { // DASSERT(self.size - from >= size); // return { self.data + from, size }; // } // template // [[nodiscard]] // INLINE auto Span_Cast(span self) -> span // { // return span { (K*)self.data, self.size * sizeof(T) / sizeof(K) }; // } // template // [[nodiscard]] // INLINE auto Span_Front(span self) -> T& // { // return self[0]; // } // template // [[nodiscard]] // INLINE auto Span_Back(span self) -> T& // { // return self[self.size - 1]; // } // template // [[nodiscard]] // INLINE auto Span_Eq(span self, span> another) -> bool // { // if (self.size == another.size) // return MemEq(self.data, another.data, Span_SizeBytes(self)); // else // return false; // } // template // [[nodiscard]] // INLINE auto Span_StartsWith(span self, span> prefix) -> bool // { // return MemStartsWith(self.data, Span_SizeBytes(self), prefix.data, Span_SizeBytes(prefix)); // } // INLINE auto StartsWithIgnoreCase(byteview self, byteview prefix) -> bool // { // if (prefix.size > self.size) // return false; // for (uint64_t i = 0; i < prefix.size; ++i) // { // if (self[i] != prefix[i] && (self[i] ^ 0x20) != prefix[i]) // return false; // } // return true; // } // template // [[nodiscard]] // INLINE auto Span_EndsWith(span self, span> suffix) -> bool // { // return MemEndsWith(self.data, Span_SizeBytes(self), suffix.data, Span_SizeBytes(suffix)); // } // template // [[nodiscard]] // INLINE auto Span_Copy(span dst, span src) // { // return MemCpy(dst.data, Span_SizeBytes(dst), src.data, Span_SizeBytes(src)); // } // INLINE auto Span_FromCStr(const void* str, uint64_t maxLength) -> byteview // { // return byteview { (uint8_t*)str, CStrLen(str, maxLength) }; // } // template // INLINE auto Span_ByteViewPtr(T* ptr) -> byteview // { // return byteview { (uint8_t*)ptr, sizeof(T) }; // } // template // INLINE auto Span_Contains(const span& self, const T& value) -> bool // { // for (auto& elem : self) { // if (elem == value) // return true; // } // return false; // } // template // INLINE auto Span_Erase(span self, T* from, T* to) -> span // { // static_assert(!std::is_const_v); // DASSERT(from >= self.begin() && from < self.end()); // DASSERT(to >= self.begin() && to <= self.end()); // DASSERT(to >= from); // if (from == to) // return self; // uint64_t numRemoved = to - from; // uint64_t numToMove = self.end() - to; // if (numToMove > 0) // MemMove(from, to, numToMove * sizeof(T)); // return { self.data, self.size - numRemoved }; // } // template // INLINE auto Span_Erase(span self, span section) -> span // { // return Span_Erase(self, section.begin(), section.end()); // } // template // INLINE auto Span_Erase(span self, T* pos) -> span // { // return Span_Erase(self, pos, pos + 1); // } // INLINE auto Span_ByteviewEq(byteview a, const char* b) -> bool // { // while (*b) { // if (a.size == 0 || a.data[0] != (uint8_t)*b) // return false; // a.data++; // a.size--; // b++; // } // return a.size == 0; // }