mirror of
https://github.com/shadps4-emu/ext-fmt.git
synced 2024-11-23 09:49:42 +00:00
Add support formatting std::expected<void, E>
Signed-off-by: Vladislav Shchapov <vladislav@shchapov.ru>
This commit is contained in:
parent
1cc10ab68f
commit
22d50c1a9c
@ -279,7 +279,8 @@ FMT_BEGIN_NAMESPACE
|
||||
FMT_EXPORT
|
||||
template <typename T, typename E, typename Char>
|
||||
struct formatter<std::expected<T, E>, Char,
|
||||
std::enable_if_t<is_formattable<T, Char>::value &&
|
||||
std::enable_if_t<(std::is_void<T>::value ||
|
||||
is_formattable<T, Char>::value) &&
|
||||
is_formattable<E, Char>::value>> {
|
||||
FMT_CONSTEXPR auto parse(parse_context<Char>& ctx) -> const Char* {
|
||||
return ctx.begin();
|
||||
@ -292,7 +293,8 @@ struct formatter<std::expected<T, E>, Char,
|
||||
|
||||
if (value.has_value()) {
|
||||
out = detail::write<Char>(out, "expected(");
|
||||
out = detail::write_escaped_alternative<Char>(out, *value);
|
||||
if constexpr (!std::is_void<T>::value)
|
||||
out = detail::write_escaped_alternative<Char>(out, *value);
|
||||
} else {
|
||||
out = detail::write<Char>(out, "unexpected(");
|
||||
out = detail::write_escaped_alternative<Char>(out, value.error());
|
||||
|
@ -140,6 +140,7 @@ TEST(std_test, optional) {
|
||||
|
||||
TEST(std_test, expected) {
|
||||
#ifdef __cpp_lib_expected
|
||||
EXPECT_EQ(fmt::format("{}", std::expected<void, int>{}), "expected()");
|
||||
EXPECT_EQ(fmt::format("{}", std::expected<int, int>{1}), "expected(1)");
|
||||
EXPECT_EQ(fmt::format("{}", std::expected<int, int>{std::unexpected(1)}),
|
||||
"unexpected(1)");
|
||||
@ -163,6 +164,7 @@ TEST(std_test, expected) {
|
||||
EXPECT_FALSE(
|
||||
(fmt::is_formattable<std::expected<int, unformattable2>>::value));
|
||||
EXPECT_TRUE((fmt::is_formattable<std::expected<int, int>>::value));
|
||||
EXPECT_TRUE((fmt::is_formattable<std::expected<void, int>>::value));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user