SSX3LobbyServer/lib/base/fixed_string.hpp

27 lines
538 B
C++
Raw Normal View History

#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