7#include "../macros.hpp"
11#include "exception.hpp"
20hi_export_module(hikogui.utility.fixed_string);
22hi_export
namespace hi {
inline namespace v1 {
41hi_export
template<
size_t N>
43 using value_type =
char;
53 template<std::
size_t O>
55 requires((O - 1) == N)
57 for (
auto i = 0
_uz; i != (O - 1); ++i) {
64 template<std::invocable F>
69 hi_assert(str.size() == N);
70 for (
auto i = 0
_uz; i != str.size(); ++i) {
77 return std::string_view{_str.
data(), size()};
96 [[
nodiscard]]
constexpr friend char& get(fixed_string& a)
noexcept
98 return std::get<I>(a._str);
102 [[
nodiscard]]
constexpr friend char const& get(fixed_string
const& a)
noexcept
104 return std::get<I>(a._str);
107 [[
nodiscard]]
constexpr char& operator[](
size_t index)
noexcept
110 if (
not(index < N)) {
117 [[
nodiscard]]
constexpr char const& operator[](
size_t index)
const noexcept
120 if (
not(index < N)) {
134 return _str.
begin() + size();
137 [[
nodiscard]]
constexpr bool operator==(fixed_string
const& rhs)
const noexcept =
default;
138 [[
nodiscard]]
constexpr auto operator<=>(fixed_string
const& rhs)
const noexcept =
default;
151 return static_cast<std::string_view
>(*this) <=>
static_cast<std::string_view
>(rhs);
154 [[
nodiscard]]
constexpr bool operator==(std::string_view rhs)
const noexcept
156 return static_cast<std::string_view
>(*this) == rhs;
159 [[
nodiscard]]
constexpr auto operator<=>(std::string_view rhs)
const noexcept
161 return static_cast<std::string_view
>(*this) <=> rhs;
166 return static_cast<std::string_view
>(*this) == rhs;
171 return static_cast<std::string_view
>(*this) <=> rhs;
174 [[
nodiscard]]
constexpr bool operator==(
char const *rhs)
const noexcept
176 return static_cast<std::string_view
>(*this) == rhs;
179 [[
nodiscard]]
constexpr auto operator<=>(
char const *rhs)
const noexcept
181 return static_cast<std::string_view
>(*this) <=> rhs;
185 [[
nodiscard]]
constexpr bool operator==(
char const (&rhs)[O])
const noexcept
187 return *
this == fixed_string<O - 1>(rhs);
191 [[
nodiscard]]
constexpr auto operator<=>(
char const (&rhs)[O])
const noexcept
193 return *
this <=> fixed_string<O - 1>(rhs);
252hi_export
template<fixed_
string Tag>
255 static_assert(Tag.size() == 4,
"fourcc must get a 4 character fixed_string");
257 return (
static_cast<uint32_t
>(
get<0>(Tag)) << 24) | (
static_cast<uint32_t
>(
get<1>(Tag)) << 16) |
258 (
static_cast<uint32_t
>(
get<2>(Tag)) << 8) |
static_cast<uint32_t
>(
get<3>(Tag));
261hi_export
template<fixed_
string Tag>
262consteval uint32_t
operator"" _fcc()
267hi_export
template<std::
size_t N>
268fixed_string(
char const (&str)[N]) -> fixed_string<N - 1>;
270hi_export
template<std::invocable F>
271fixed_string(F
const& f) -> fixed_string<F{}().size()>;
274#define hi_to_fixed_string(x) ::hi::fixed_string{[]{ return x; }}
281hi_export
template<std::
size_t N>
282struct formatter<
hi::fixed_string<N>, char> : formatter<std::string_view, char> {
285 return std::formatter<std::string_view, char>::format(
static_cast<std::string_view
>(t), fc);
Utilities to assert and bound check.
Functions for casting values between types savely.
Utilities for throwing exceptions and terminating the application.
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
The HikoGUI namespace.
Definition recursive_iterator.hpp:15
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:378
A string which may be used as a none-type template parameter.
Definition fixed_string.hpp:42
constexpr auto operator/(fixed_string< R > const &rhs) const noexcept
Join two strings with a slash '/'.
Definition fixed_string.hpp:224
constexpr fixed_string(F const &f) noexcept
Create a fixed string from function returning a string-like.
Definition fixed_string.hpp:65
constexpr auto operator+(fixed_string< R > const &rhs) const noexcept
Append two strings.
Definition fixed_string.hpp:199