4#include "../Foundation/Compiler.h"
5#include "../Foundation/Span.h"
16template <
typename T, u
int32_t N>
22 operator Span<const T>()
const {
return {values, size}; }
27 [[nodiscard]]
constexpr bool contains(T value,
uint32_t* outIndex =
nullptr)
const
31 if (values[i] == value)
45 template <u
int32_t N2>
46 [[nodiscard]]
constexpr bool append(
const ArrayWithSize<T, N2>& other)
48 if (size + other.size >= N)
50 for (
uint32_t i = 0; i < other.size; ++i)
52 values[size++] = other.values[i];
60 [[nodiscard]]
constexpr bool push_back(
const T& value)
64 values[size++] = value;
70 bool equals(Span<const T> other)
const
72 return size == other.sizeInElements() and ::memcmp(values, other.data(), other.sizeInBytes()) == 0;
77template <
typename Type>
83 constexpr WritableRange(Type* iteratorStart,
const uint32_t capacity)
84 : iterator(iteratorStart), iteratorEnd(iteratorStart + capacity)
87 [[nodiscard]]
constexpr bool writeAndAdvance(
const Type& value)
89 if (iterator < iteratorEnd)
106 constexpr Sv() : data(nullptr), length(0) {}
111 constexpr Sv(
const char* data,
uint32_t length) : data(data), length(length) {}
116 template <u
int32_t N>
117 constexpr Sv(
const char (&data)[N]) : data(data), length(N - 1)
120 constexpr bool operator==(
const Sv other)
const
122 if (length != other.length)
124 for (
uint32_t idx = 0; idx < length; ++idx)
126 if (data[idx] != other.data[idx])
137static constexpr Sv ClNm()
140#if SC_COMPILER_CLANG || SC_COMPILER_GCC
141 const char* name = __PRETTY_FUNCTION__;
142 constexpr char separating_char =
'=';
146 const char* it = name;
147 while (*it != separating_char)
150 while (it[length] != 0)
152 return Sv(it, length - trim_chars);
154 const char* name = __FUNCSIG__;
155 constexpr char separating_char =
'<';
156 constexpr char ending_char =
'>';
157 const char* it = name;
158 while (*it != separating_char)
160 auto itStart = it + 1;
161 while (*it != ending_char)
167 return Sv(itStart,
static_cast<int>(it - itStart));
172using TypeStringView = Sv;
179#if SC_LANGUAGE_CPP_AT_LEAST_17
182 [[nodiscard]]
static constexpr auto TrimClassName()
184 constexpr auto className = ClNm<T>();
186 ArrayWithSize<char, className.length> trimmedName;
187 for (
uint32_t i = 0; i < className.length; ++i)
189 trimmedName.values[i] = className.data[i];
191 trimmedName.size = className.length;
196 static inline constexpr auto value = TrimClassName();
199 [[nodiscard]]
static constexpr TypeStringView get() {
return TypeStringView(value.values, value.size); }
201 [[nodiscard]]
static constexpr TypeStringView get()
203 auto className = ClNm<T>();
204 return TypeStringView(className.data, className.length);
unsigned int uint32_t
Platform independent (4) bytes unsigned int.
Definition PrimitiveTypes.h:38