-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Closed
Labels
Description
Consider adding a formatter for std::expected<void, E>:
template <typename E, typename Char>
struct formatter<std::expected<void, E>, Char,
std::enable_if_t<is_formattable<E, Char>::value>> {
FMT_CONSTEXPR auto parse(parse_context<Char>& ctx) -> const Char* {
return ctx.begin();
}
template <typename FormatContext>
auto format(const std::expected<void, E>& value, FormatContext& ctx) const
-> decltype(ctx.out()) {
auto out = ctx.out();
if (value.has_value()) {
out = detail::write<Char>(out, "expected(");
} else {
out = detail::write<Char>(out, "unexpected(");
out = detail::write_escaped_alternative<Char>(out, value.error());
}
*out++ = ')';
return out;
}
};Output
expected()when there is no error