27template <
typename Char,
typename Traits,
size_t N>
33 requires(M <= (N + 1))
35 if constexpr (M == (N + 1)) {
37 throw std::logic_error{
"char array not null terminated"};
43 auto p = chars.
begin();
48 while (p != chars.end()) {
53 explicit constexpr ct_string(std::basic_string_view<Char, Traits> s) {
56 auto p = chars.begin();
61 while (p != chars.end()) {
68 constexpr bool operator==(
const std::basic_string<Char, Traits>& rhs)
const {
69 if (size() != rhs.size()) {
73 for (
size_t i = 0; i < size(); ++i) {
74 if (chars[i] != rhs[i]) {
82 constexpr bool operator==(std::basic_string_view<Char, Traits> rhs)
const {
83 if (size() != rhs.size()) {
87 for (
size_t i = 0; i < size(); ++i) {
88 if (chars[i] != rhs[i]) {
98 constexpr bool operator==(Char
const (&rhs)[M])
const {
99 for (
size_t i = 0; i < M; ++i) {
100 if (chars[i] != rhs[i]) {
109 for (
size_t i = 0; i < N + 1; ++i) {
110 if (chars[i] != rhs[i]) {
116 if (rhs[i] ==
'\0' && i < N) {
124 constexpr auto size() const noexcept {
return N; }
126 constexpr auto begin() const noexcept {
return chars.begin(); }
127 constexpr auto end() const noexcept {
return chars.begin() + N; }
129 constexpr auto data() const noexcept {
return chars.data(); }
130 constexpr auto c_str() const noexcept {
return chars.data(); }
132 constexpr operator std::basic_string<Char, Traits>()
134 return std::basic_string<Char, Traits>{chars.data(), N};
137 constexpr operator std::basic_string_view<Char, Traits>()
139 return std::basic_string_view<Char, Traits>{chars.data(), N};
143template <
typename Char,
size_t M>
147template <ct_
string S>
148constexpr auto operator""_ct_string() {
153template <
typename Char,
typename Traits,
size_t N1,
size_t N2>
167template <
typename Char,
typename Traits,
size_t N1,
size_t... N>
171 constexpr Char dummy[1] = {};
172 auto res =
ct_string<Char, Traits, (N1 + ... + N)>{dummy};
174 auto p = res.
chars.begin();
175 auto append = [&p](
auto&& s) {
183 (append(s1), ..., append(s));
199template <intmax_t N,
int Base = 10,
typename Char = char,
200 typename Traits = std::char_traits<Char>>
201 requires(Base >= 2 && Base <= 36)
203 constexpr char digits[] =
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
206 size_t len = N > 0 ? 0 : 1;
207 for (
auto n = N; n; len++, n /= Base) {
211 constexpr size_t size = buflen();
213 constexpr Char dummy[1] = {};
216 auto ptr = res.chars.data() + size;
218 for (
auto n = N; n; n /= Base) {
219 *--
ptr = digits[(N < 0 ? -1 : 1) * (n % Base)];
static constexpr const velocity::meters_per_second_t c(299792458.0)
Speed of light in vacuum.
UnitTypeLhs() max(const UnitTypeLhs &lhs, const UnitTypeRhs &rhs)
Definition: base.h:3417
Definition: ntcore_cpp.h:26
constexpr auto NumToCtString()
Converts any integral to a ct_string at compile-time.
Definition: ct_string.h:202
constexpr auto Concat(ct_string< Char, Traits, N1 > const &s1, ct_string< Char, Traits, N > const &... s)
Concatenates multiple fixed_strings into a larger fixed_string at compile time.
Definition: ct_string.h:168
constexpr auto operator+(ct_string< Char, Traits, N1 > const &s1, ct_string< Char, Traits, N2 > const &s2) noexcept
Definition: ct_string.h:154
ct_string(Char const (&s)[M]) -> ct_string< Char, std::char_traits< Char >, M - 1 >
Fixed length string (array of character) for compile time use.
Definition: ct_string.h:29
constexpr auto end() const noexcept
Definition: ct_string.h:127
constexpr bool operator==(std::basic_string_view< Char, Traits > rhs) const
Definition: ct_string.h:82
constexpr bool operator==(const ct_string< Char, Traits, N > &) const =default
constexpr bool operator==(const Char *rhs) const
Definition: ct_string.h:108
constexpr auto size() const noexcept
Definition: ct_string.h:124
constexpr auto begin() const noexcept
Definition: ct_string.h:126
constexpr ct_string(std::basic_string_view< Char, Traits > s)
Definition: ct_string.h:53
constexpr bool operator==(const std::basic_string< Char, Traits > &rhs) const
Definition: ct_string.h:68
constexpr auto data() const noexcept
Definition: ct_string.h:129
constexpr auto c_str() const noexcept
Definition: ct_string.h:130
std::array< Char, N+1 > chars
Definition: ct_string.h:30
#define S(label, offset, message)
Definition: Errors.h:119