diff options
| author | Felix Morgner <felix.morgner@ost.ch> | 2026-03-19 17:05:26 +0100 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@ost.ch> | 2026-03-19 17:05:26 +0100 |
| commit | 63395fecd439989734f80e6420e4961557465ff9 (patch) | |
| tree | ee3225149752371ddd7be908100a85f1679b5834 /libs | |
| parent | 6c9e50bee8362bd87c66ee10c253d94a78e1459c (diff) | |
| download | teachos-63395fecd439989734f80e6420e4961557465ff9.tar.xz teachos-63395fecd439989734f80e6420e4961557465ff9.zip | |
kstd/format: enable formatting of bool values
Diffstat (limited to 'libs')
| -rw-r--r-- | libs/kstd/include/kstd/bits/formatter.hpp | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/libs/kstd/include/kstd/bits/formatter.hpp b/libs/kstd/include/kstd/bits/formatter.hpp index eadc0ef..a467edd 100644 --- a/libs/kstd/include/kstd/bits/formatter.hpp +++ b/libs/kstd/include/kstd/bits/formatter.hpp @@ -95,7 +95,7 @@ namespace kstd auto prefix = std::array<char, 2>{'0', '\0'}; auto prefix_length = 0uz; - if (specs.alternative_form && value != 0) + if (specs.alternative_form) { switch (base) { @@ -259,6 +259,29 @@ namespace kstd { }; + template<> + struct formatter<bool> + { + bits::format_specs specs{}; + + constexpr auto parse(std::string_view context) -> std::string_view + { + return bits::parse_specs(context, specs); + } + + auto format(bool value, format_context & context) const -> void + { + if (specs.type == 's' || specs.type == '\0') + { + context.push(value ? "true" : "false"); + } + else + { + formatter<int>{specs}.format(static_cast<int>(value), context); + } + } + }; + struct format_arg { using formatting_function = std::string_view(void const *, std::string_view, format_context &); |
