Add a formatter specialization for std::error_code.

This commit is contained in:
Владислав Щапов
2021-05-09 06:29:39 -07:00
committed by Victor Zverovich
parent 39f28424ca
commit 4211d86539
2 changed files with 41 additions and 0 deletions
+17
View File
@@ -129,6 +129,23 @@ class error_code {
int get() const FMT_NOEXCEPT { return value_; }
};
template <typename Char> struct formatter<std::error_code, Char> {
template <typename ParseContext>
FMT_CONSTEXPR auto parse(ParseContext& ctx) -> decltype(ctx.begin()) {
return ctx.begin();
}
template <typename FormatContext>
FMT_CONSTEXPR auto format(const std::error_code& ec, FormatContext& ctx) const
-> decltype(ctx.out()) {
auto out = ctx.out();
out = detail::write<Char>(out, to_string_view(ec.category().name()));
out = detail::write<Char>(out, Char(':'));
out = detail::write<Char>(out, ec.value());
return out;
}
};
#ifdef _WIN32
namespace detail {
// A converter from UTF-16 to UTF-8.