From 63395fecd439989734f80e6420e4961557465ff9 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Thu, 19 Mar 2026 17:05:26 +0100 Subject: kstd/format: enable formatting of bool values --- libs/kstd/include/kstd/bits/formatter.hpp | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'libs/kstd') 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{'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 + { + 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{specs}.format(static_cast(value), context); + } + } + }; + struct format_arg { using formatting_function = std::string_view(void const *, std::string_view, format_context &); -- cgit v1.2.3