diff options
Diffstat (limited to 'libs/kstd')
| -rw-r--r-- | libs/kstd/kstd/format.hpp | 1 | ||||
| -rw-r--r-- | libs/kstd/kstd/system_error.hpp | 25 |
2 files changed, 26 insertions, 0 deletions
diff --git a/libs/kstd/kstd/format.hpp b/libs/kstd/kstd/format.hpp index 5ed798db..5d7f4ae6 100644 --- a/libs/kstd/kstd/format.hpp +++ b/libs/kstd/kstd/format.hpp @@ -5,6 +5,7 @@ #include <kstd/bits/format/arg.hpp> #include <kstd/bits/format/args.hpp> #include <kstd/bits/format/context.hpp> +#include <kstd/bits/format/error.hpp> #include <kstd/bits/format/formatter.hpp> #include <kstd/bits/format/formatter/bool.hpp> #include <kstd/bits/format/formatter/byte.hpp> diff --git a/libs/kstd/kstd/system_error.hpp b/libs/kstd/kstd/system_error.hpp index f971703b..08725609 100644 --- a/libs/kstd/kstd/system_error.hpp +++ b/libs/kstd/kstd/system_error.hpp @@ -1,6 +1,8 @@ #ifndef KSTD_SYSTEM_ERROR_HPP #define KSTD_SYSTEM_ERROR_HPP +#include <kstd/format.hpp> + #include <compare> #include <cstdint> #include <functional> @@ -472,6 +474,29 @@ namespace kstd return {static_cast<int>(value), generic_category()}; } + template<> + struct formatter<error_code> + { + constexpr auto parse(format_parse_context & context) -> format_parse_context::iterator + { + auto it = context.begin(); + if (it != context.end() && *it != '}') + { + bits::format::error("Invalid specifier for string_view."); + } + return it; + } + + auto format(error_code const & error, format_context & context) const -> void + { + context.push(error.category().name()); + context.push(':'); + formatter<int>{}.format(error.value(), context); + context.push(':'); + context.push(error.message()); + } + }; + } // namespace kstd #endif |
