2022-09-05 04:24:50 -04:00
|
|
|
//
|
2022-09-05 20:59:46 -04:00
|
|
|
// EuropaTools
|
2022-09-05 04:24:50 -04:00
|
|
|
//
|
|
|
|
// (C) 2021-2022 modeco80 <lily.modeco80@protonmail.ch>
|
|
|
|
//
|
2022-09-05 20:59:46 -04:00
|
|
|
// SPDX-License-Identifier: LGPL-3.0-or-later
|
2022-09-05 04:24:50 -04:00
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef EUROPA_UTIL_FIXEDSTRING_H
|
|
|
|
#define EUROPA_UTIL_FIXEDSTRING_H
|
|
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
|
|
|
|
namespace europa::util {
|
|
|
|
|
2022-09-05 20:59:46 -04:00
|
|
|
/**
|
|
|
|
* A compile-time string. Usable as a C++20 cNTTP.
|
|
|
|
*/
|
2022-09-05 04:24:50 -04:00
|
|
|
template<std::size_t 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 std::size_t Length() const {
|
|
|
|
return N;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<std::size_t N>
|
|
|
|
FixedString(char const (&)[N]) -> FixedString<N - 1>;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // EUROPA_UTIL_FIXEDSTRING_H
|