Go to the documentation of this file.
9 #ifndef EAGINE_FIXED_SIZE_STR_HPP
10 #define EAGINE_FIXED_SIZE_STR_HPP
22 template <span_
size_t N>
28 std::memset(_str,
'\0', N);
32 template <
typename... C,
typename = std::enable_if_t<
sizeof...(C) == N>>
38 std::strncpy(_str, s, N);
39 EAGINE_ASSERT(_str[N - 1] ==
'\0');
45 typename = std::enable_if_t<N1 + N2 == N + 1>>
49 std::strncpy(_str, s1._str, N1);
50 std::strncpy(_str + N1 - 1, s2._str, N2);
64 return _str[0] ==
'\0';
73 auto data() const noexcept {
74 return static_cast<const char*
>(_str);
81 EAGINE_ASSERT(_str[N - 1] ==
'\0');
107 return {_str, N - 1};
117 static_assert(N > 0,
"Zero-length fixed size strings are not supported");
121 template <span_
size_t>
122 friend class fixed_size_string;
127 template <span_
size_t N>
134 template <span_
size_t N1, span_
size_t N2>
146 std::enable_if_t<(I >= 0) && (I < 10)>* =
nullptr) noexcept {
155 std::enable_if_t<(I > 9)>* =
nullptr) noexcept {
165 std::enable_if_t<(I < 0)>* =
nullptr) noexcept {
171 #endif // EAGINE_FIXED_SIZE_STR_HPP
auto size() const noexcept -> span_size_t
Returns the size of the string.
Definition: fixed_size_str.hpp:68
std::ptrdiff_t span_size_t
Signed span size type used by eagine.
Definition: types.hpp:36
basic_string_span< const char > string_view
Alias for const string views.
Definition: string_span.hpp:116
static auto to_fixed_size_string(int_constant< I >, std::enable_if_t<(I >=0) &&(I< 10)> *=nullptr) noexcept
Converts a single-digit decimal number into fixed_size_string.
Definition: fixed_size_str.hpp:144
Common code is placed in this namespace.
Definition: eagine.hpp:21
static auto make_fixed_size_string(const char(&str)[N]) noexcept
Creates a fixed_size_string from a C-string literal.
Definition: fixed_size_str.hpp:128
fixed_size_string(const char(&s)[N]) noexcept
Construction from a C-string literal.
Definition: fixed_size_str.hpp:37
char * iterator
Alias for iterator type.
Definition: fixed_size_str.hpp:57
span_size_t size_type
Alias for length type.
Definition: fixed_size_str.hpp:54
auto begin() noexcept -> iterator
Returns iterator to the start of the string.
Definition: fixed_size_str.hpp:86
auto view() const noexcept -> string_view
Returns a view over the internal character data storage.
Definition: fixed_size_str.hpp:106
static auto operator+(const fixed_size_string< N1 > &s1, const fixed_size_string< N2 > &s2) noexcept
Concatenation operator for fixed_size_string.
Definition: fixed_size_str.hpp:135
auto end() const noexcept -> const_iterator
Returns const iterator past the end of the string.
Definition: fixed_size_str.hpp:101
auto end() noexcept -> iterator
Returns iterator past the end of the string.
Definition: fixed_size_str.hpp:96
fixed_size_string() noexcept
Default construction.
Definition: fixed_size_str.hpp:27
const char * const_iterator
Alias for const iterator type.
Definition: fixed_size_str.hpp:60
auto empty() const noexcept
Indicates if the string is empty.
Definition: fixed_size_str.hpp:63
auto data() const noexcept
Returns pointer to the internally-stored character data.
Definition: fixed_size_str.hpp:73
std::integral_constant< int, I > int_constant
Alias for signed int constant type.
Definition: int_constant.hpp:25
constexpr fixed_size_string(C... c) noexcept
Construction from a pack of characters.
Definition: fixed_size_str.hpp:33
String with maximum fixed-size internal storage.
Definition: fixed_size_str.hpp:23
auto begin() const noexcept -> const_iterator
Returns const iterator to the start of the string.
Definition: fixed_size_str.hpp:91
auto c_str() const noexcept
Returns pointer to the internally-stored character data.
Definition: fixed_size_str.hpp:80