12#include "../macros.hpp"
15#include "debugger.hpp"
16#include "exception.hpp"
19hi_export_module(hikogui.utility.fixed_string);
21hi_export
namespace hi {
inline namespace v1 {
42 using value_type =
char;
52 template<std::
size_t O>
54 requires((O - 1) == N)
56 for (
auto i = 0
_uz; i != (O - 1); ++i) {
63 template<std::invocable F>
68 hi_assert(str.size() == N);
69 for (
auto i = 0
_uz; i != str.size(); ++i) {
76 return std::string_view{_str.
data(), size()};
95 [[
nodiscard]]
constexpr friend char& get(fixed_string& a)
noexcept
97 return std::get<I>(a._str);
101 [[
nodiscard]]
constexpr friend char const& get(fixed_string
const& a)
noexcept
103 return std::get<I>(a._str);
106 [[
nodiscard]]
constexpr char& operator[](
size_t index)
noexcept
109 if (
not(index < N)) {
116 [[
nodiscard]]
constexpr char const& operator[](
size_t index)
const noexcept
119 if (
not(index < N)) {
133 return _str.
begin() + size();
136 [[
nodiscard]]
constexpr bool operator==(fixed_string
const& rhs)
const noexcept =
default;
137 [[
nodiscard]]
constexpr auto operator<=>(fixed_string
const& rhs)
const noexcept =
default;
150 return static_cast<std::string_view
>(*this) <=>
static_cast<std::string_view
>(rhs);
153 [[
nodiscard]]
constexpr bool operator==(std::string_view rhs)
const noexcept
155 return static_cast<std::string_view
>(*this) == rhs;
158 [[
nodiscard]]
constexpr auto operator<=>(std::string_view rhs)
const noexcept
160 return static_cast<std::string_view
>(*this) <=> rhs;
165 return static_cast<std::string_view
>(*this) == rhs;
170 return static_cast<std::string_view
>(*this) <=> rhs;
173 [[
nodiscard]]
constexpr bool operator==(
char const *rhs)
const noexcept
175 return static_cast<std::string_view
>(*this) == rhs;
178 [[
nodiscard]]
constexpr auto operator<=>(
char const *rhs)
const noexcept
180 return static_cast<std::string_view
>(*this) <=> rhs;
184 [[
nodiscard]]
constexpr bool operator==(
char const (&rhs)[O])
const noexcept
186 return *
this == fixed_string<O - 1>(rhs);
190 [[
nodiscard]]
constexpr auto operator<=>(
char const (&rhs)[O])
const noexcept
192 return *
this <=> fixed_string<O - 1>(rhs);
251template<fixed_
string Tag>
254 static_assert(Tag.size() == 4,
"fourcc must get a 4 character fixed_string");
256 return (
static_cast<uint32_t
>(
get<0>(Tag)) << 24) | (
static_cast<uint32_t
>(
get<1>(Tag)) << 16) |
257 (
static_cast<uint32_t
>(
get<2>(Tag)) << 8) |
static_cast<uint32_t
>(
get<3>(Tag));
260template<fixed_
string Tag>
261consteval uint32_t
operator"" _fcc()
266template<std::
size_t N>
267fixed_string(
char const (&str)[N]) -> fixed_string<N - 1>;
269template<std::invocable F>
270fixed_string(F
const& f) -> fixed_string<std::ranges::size(F{}())>;
272#define hi_to_fixed_string(x) \
282hi_export
template<std::
size_t N,
typename CharT>
283struct std::formatter<
hi::fixed_string<N>, CharT> : std::formatter<std::string_view, CharT> {
286 return std::formatter<std::string_view, CharT>::format(
static_cast<std::string_view
>(t), fc);
Utilities to assert and bound check.
Functions for casting values between types savely.
DOXYGEN BUG.
Definition algorithm.hpp:16
geometry/margins.hpp
Definition lookahead_iterator.hpp:5
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:377
A string which may be used as a none-type template parameter.
Definition fixed_string.hpp:41
constexpr auto operator/(fixed_string< R > const &rhs) const noexcept
Join two strings with a slash '/'.
Definition fixed_string.hpp:223
constexpr fixed_string(F const &f) noexcept
Create a fixed string from function returning a string-like.
Definition fixed_string.hpp:64
constexpr auto operator+(fixed_string< R > const &rhs) const noexcept
Append two strings.
Definition fixed_string.hpp:198