16namespace hi::inline
v1 {
37 using value_type = char;
47 template<std::
size_t O>
49 requires((O - 1) == N)
51 for (
auto i = 0_uz; i != (O - 1); ++i) {
58 template<std::invocable F>
64 for (
auto i = 0_uz; i != str.size(); ++i) {
65 _str[i] = char_cast<char>(str[i]);
69 constexpr operator std::string_view() const noexcept
71 return std::string_view{_str.
data(), size()};
79 [[nodiscard]]
constexpr std::size_t size() const noexcept
84 [[nodiscard]]
constexpr bool empty() const noexcept
90 [[nodiscard]]
constexpr friend char& get(fixed_string& a)
noexcept
92 return std::get<I>(a._str);
96 [[nodiscard]]
constexpr friend char const& get(fixed_string
const& a)
noexcept
98 return std::get<I>(a._str);
101 [[nodiscard]]
constexpr char& operator[](
size_t index)
noexcept
104 if (not(index < N)) {
111 [[nodiscard]]
constexpr char const& operator[](
size_t index)
const noexcept
114 if (not(index < N)) {
121 [[nodiscard]]
constexpr auto begin() noexcept
126 [[nodiscard]]
constexpr auto end() noexcept
128 return _str.
begin() + size();
131 [[nodiscard]]
constexpr bool operator==(fixed_string
const& rhs)
const noexcept =
default;
132 [[nodiscard]]
constexpr auto operator<=>(fixed_string
const& rhs)
const noexcept =
default;
135 [[nodiscard]]
constexpr bool operator==(fixed_string<O>
const& rhs)
const noexcept
142 [[nodiscard]]
constexpr auto operator<=>(fixed_string<O>
const& rhs)
const noexcept
145 return static_cast<std::string_view
>(*this) <=>
static_cast<std::string_view
>(rhs);
148 [[nodiscard]]
constexpr bool operator==(std::string_view rhs)
const noexcept
150 return static_cast<std::string_view
>(*this) == rhs;
153 [[nodiscard]]
constexpr auto operator<=>(std::string_view rhs)
const noexcept
155 return static_cast<std::string_view
>(*this) <=> rhs;
158 [[nodiscard]]
constexpr bool operator==(
std::string const& rhs)
const noexcept
160 return static_cast<std::string_view
>(*this) == rhs;
163 [[nodiscard]]
constexpr auto operator<=>(
std::string const& rhs)
const noexcept
165 return static_cast<std::string_view
>(*this) <=> rhs;
168 [[nodiscard]]
constexpr bool operator==(
char const *rhs)
const noexcept
170 return static_cast<std::string_view
>(*this) == rhs;
173 [[nodiscard]]
constexpr auto operator<=>(
char const *rhs)
const noexcept
175 return static_cast<std::string_view
>(*this) <=> rhs;
179 [[nodiscard]]
constexpr bool operator==(
char const (&rhs)[O])
const noexcept
181 return *
this == fixed_string<O - 1>(rhs);
185 [[nodiscard]]
constexpr auto operator<=>(
char const (&rhs)[O])
const noexcept
187 return *this <=> fixed_string<O - 1>(rhs);
197 for (
auto src_i = 0_uz; src_i != N; ++src_i, ++dst_i) {
198 r[dst_i] = (*this)[src_i];
200 for (
auto src_i = 0_uz; src_i != R; ++src_i, ++dst_i) {
201 r[dst_i] = rhs[src_i];
208 [[nodiscard]]
constexpr auto operator+(
char const (&rhs)[R])
const noexcept
220 constexpr auto has_dot = N != 0 and R != 0 ? 1_uz : 0_uz;
224 for (
auto src_i = 0_uz; src_i != N; ++src_i, ++dst_i) {
225 r[dst_i] = (*this)[src_i];
232 for (
auto src_i = 0_uz; src_i != R; ++src_i, ++dst_i) {
233 r[dst_i] = rhs[src_i];
240 [[nodiscard]]
constexpr auto operator/(
char const (&rhs)[R])
const noexcept
246template<fixed_
string Tag>
247[[nodiscard]]
consteval uint32_t fourcc() noexcept
249 static_assert(Tag.size() == 4,
"fourcc must get a 4 character fixed_string");
251 return (
static_cast<uint32_t
>(get<0>(Tag)) << 24) | (
static_cast<uint32_t
>(get<1>(Tag)) << 16) |
252 (
static_cast<uint32_t
>(get<2>(Tag)) << 8) |
static_cast<uint32_t
>(get<3>(Tag));
255template<fixed_
string Tag>
256consteval uint32_t
operator"" _fcc()
258 return fourcc<Tag>();
261template<std::
size_t N>
262fixed_string(
char const (&str)[N]) -> fixed_string<N - 1>;
264template<std::invocable F>
265fixed_string(F
const& f) -> fixed_string<std::ranges::size(F{}())>;
267#define hi_to_fixed_string(x) \
277template<std::
size_t N,
typename CharT>
278struct std::formatter<
hi::fixed_string<N>, CharT> : std::formatter<std::string_view, CharT> {
279 constexpr auto format(hi::fixed_string<N>
const& t,
auto& fc)
281 return std::formatter<std::string_view, CharT>::format(
static_cast<std::string_view
>(t), fc);
Utilities to assert and bound check.
#define hi_assert(expression,...)
Assert if expression is true.
Definition assert.hpp:199
Utilities used by the HikoGUI library itself.
Functions for casting values between types savely.
DOXYGEN BUG.
Definition algorithm.hpp:13
geometry/margins.hpp
Definition cache.hpp:11
A string which may be used as a none-type template parameter.
Definition fixed_string.hpp:36
constexpr auto operator/(fixed_string< R > const &rhs) const noexcept
Join two strings with a slash '/'.
Definition fixed_string.hpp:218
constexpr fixed_string(F const &f) noexcept
Create a fixed string from function returning a string-like.
Definition fixed_string.hpp:59
constexpr auto operator+(fixed_string< R > const &rhs) const noexcept
Append two strings.
Definition fixed_string.hpp:193