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
85 [[nodiscard]]
constexpr friend char& get(fixed_string& a)
noexcept
87 return std::get<I>(a._str);
91 [[nodiscard]]
constexpr friend char const& get(fixed_string
const& a)
noexcept
93 return std::get<I>(a._str);
96 [[nodiscard]]
constexpr char& operator[](
size_t index)
noexcept
106 [[nodiscard]]
constexpr char const& operator[](
size_t index)
const noexcept
109 if (not(index < N)) {
116 [[nodiscard]]
constexpr auto begin() noexcept
121 [[nodiscard]]
constexpr auto end() noexcept
123 return _str.
begin() + size();
126 [[nodiscard]]
constexpr bool operator==(fixed_string
const& rhs)
const noexcept =
default;
127 [[nodiscard]]
constexpr auto operator<=>(fixed_string
const& rhs)
const noexcept =
default;
130 [[nodiscard]]
constexpr bool operator==(fixed_string<O>
const& rhs)
const noexcept
137 [[nodiscard]]
constexpr auto operator<=>(fixed_string<O>
const& rhs)
const noexcept
140 return static_cast<std::string_view
>(*this) <=>
static_cast<std::string_view
>(rhs);
143 [[nodiscard]]
constexpr bool operator==(std::string_view rhs)
const noexcept
145 return static_cast<std::string_view
>(*this) == rhs;
148 [[nodiscard]]
constexpr auto operator<=>(std::string_view rhs)
const noexcept
150 return static_cast<std::string_view
>(*this) <=> rhs;
153 [[nodiscard]]
constexpr bool operator==(
std::string const& rhs)
const noexcept
155 return static_cast<std::string_view
>(*this) == rhs;
158 [[nodiscard]]
constexpr auto operator<=>(
std::string const& rhs)
const noexcept
160 return static_cast<std::string_view
>(*this) <=> rhs;
163 [[nodiscard]]
constexpr bool operator==(
char const *rhs)
const noexcept
165 return static_cast<std::string_view
>(*this) == rhs;
168 [[nodiscard]]
constexpr auto operator<=>(
char const *rhs)
const noexcept
170 return static_cast<std::string_view
>(*this) <=> rhs;
174 [[nodiscard]]
constexpr bool operator==(
char const (&rhs)[O])
const noexcept
176 return *
this == fixed_string<O - 1>(rhs);
180 [[nodiscard]]
constexpr auto operator<=>(
char const (&rhs)[O])
const noexcept
182 return *this <=> fixed_string<O - 1>(rhs);
186 [[nodiscard]]
constexpr auto operator+(fixed_string<O>
const& rhs)
const noexcept
188 auto r = fixed_string<N + O>{};
190 for (
auto src_i = 0_uz; src_i != N; ++src_i, ++dst_i) {
191 r[dst_i] = (*this)[src_i];
193 for (
auto src_i = 0_uz; src_i != O; ++src_i, ++dst_i) {
194 r[dst_i] = rhs[src_i];
201template<fixed_
string Tag>
202[[nodiscard]]
consteval uint32_t fourcc() noexcept
204 static_assert(Tag.size() == 4,
"fourcc must get a 4 character fixed_string");
206 return (
static_cast<uint32_t
>(get<0>(Tag)) << 24) | (
static_cast<uint32_t
>(get<1>(Tag)) << 16) |
207 (
static_cast<uint32_t
>(get<2>(Tag)) << 8) |
static_cast<uint32_t
>(get<3>(Tag));
210template<fixed_
string Tag>
211consteval uint32_t
operator"" _fcc()
213 return fourcc<Tag>();
216template<std::
size_t N>
217fixed_string(
char const (&str)[N]) -> fixed_string<N - 1>;
219template<std::invocable F>
220fixed_string(F
const& f) -> fixed_string<std::ranges::size(F{}())>;
222#define hi_to_fixed_string(x) \
232template<std::
size_t N,
typename CharT>
233struct std::formatter<
hi::fixed_string<N>, CharT> : std::formatter<std::string_view, CharT> {
234 constexpr auto format(hi::fixed_string<N>
const& t,
auto& fc)
236 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:184
Utilities used by the HikoGUI library itself.
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 fixed_string(F const &f) noexcept
Create a fixed string from function returning a string-like.
Definition fixed_string.hpp:59