27 lines
538 B
C++
27 lines
538 B
C++
#pragma once
|
|
#include <base/types.hpp>
|
|
|
|
namespace base {
|
|
|
|
/// A compile time fixed string, fit for usage as a C++20 cNTTP.
|
|
template <usize N>
|
|
struct FixedString {
|
|
char buf[N + 1] {};
|
|
|
|
constexpr FixedString(const char* s) { // NOLINT
|
|
for(unsigned i = 0; i != N; ++i)
|
|
buf[i] = s[i];
|
|
}
|
|
|
|
constexpr operator const char*() const { // NOLINT
|
|
return buf;
|
|
}
|
|
|
|
[[nodiscard]] constexpr usize Length() const {
|
|
return N;
|
|
}
|
|
};
|
|
|
|
template <usize N>
|
|
FixedString(char const (&)[N]) -> FixedString<N - 1>;
|
|
} // namespace base
|