From 8042003647b50e9fddfe500677a132130449d69e Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Thu, 18 Dec 2025 14:00:03 +0100 Subject: kapi/cio: implement formatted printing --- kapi/include/kapi/cio.hpp | 55 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) (limited to 'kapi/include') diff --git a/kapi/include/kapi/cio.hpp b/kapi/include/kapi/cio.hpp index 071e6cb..98c715b 100644 --- a/kapi/include/kapi/cio.hpp +++ b/kapi/include/kapi/cio.hpp @@ -3,8 +3,12 @@ #include "kapi/cio/output_device.hpp" // IWYU pragma: export +#include + +#include #include #include +#include namespace teachos::cio { @@ -46,6 +50,57 @@ namespace teachos::cio //! //! @param text The error text to print. auto println_error(std::string_view text) -> void; + + template + // NOLINTNEXTLINE(cppcoreguidelines-missing-std-forward) + auto print(kstd::format_string...> format, Args &&... args) -> void + { + auto vprint(std::string_view format, kstd::format_args args) -> void; + auto arguments = std::array{ + kstd::format_arg{&args, kstd::format_dispatcher>} + ... + }; + vprint(format.str, kstd::format_args{arguments.data(), sizeof...(Args)}); + } + + template + // NOLINTNEXTLINE(cppcoreguidelines-missing-std-forward) + auto println(kstd::format_string...> format, Args &&... args) -> void + { + auto vprint(std::string_view format, kstd::format_args args) -> void; + auto arguments = std::array{ + kstd::format_arg{&args, kstd::format_dispatcher>} + ... + }; + vprint(format.str, kstd::format_args{arguments.data(), sizeof...(Args)}); + println(""); + } + + template + // NOLINTNEXTLINE(cppcoreguidelines-missing-std-forward) + auto print_error(kstd::format_string...> format, Args &&... args) -> void + { + auto vprint_error(std::string_view format, kstd::format_args args) -> void; + auto arguments = std::array{ + kstd::format_arg{&args, kstd::format_dispatcher>} + ... + }; + vprint_error(format.str, kstd::format_args{arguments.data(), sizeof...(Args)}); + } + + template + // NOLINTNEXTLINE(cppcoreguidelines-missing-std-forward) + auto println_error(kstd::format_string...> format, Args &&... args) -> void + { + auto vprint_error(std::string_view format, kstd::format_args args) -> void; + auto arguments = std::array{ + kstd::format_arg{&args, kstd::format_dispatcher>} + ... + }; + vprint_error(format.str, kstd::format_args{arguments.data(), sizeof...(Args)}); + println_error(""); + } + } // namespace teachos::cio #endif -- cgit v1.2.3