diff --git a/include/fmt/std.h b/include/fmt/std.h index 511b2932..88783618 100644 --- a/include/fmt/std.h +++ b/include/fmt/std.h @@ -373,11 +373,6 @@ struct formatter, Char, std::enable_if_t::value>> { private: formatter, Char> underlying_; - static constexpr basic_string_view optional = - detail::string_literal{}; - static constexpr basic_string_view none = - detail::string_literal{}; public: FMT_CONSTEXPR auto parse(parse_context& ctx) { @@ -388,10 +383,10 @@ struct formatter, Char, template auto format(const std::optional& opt, FormatContext& ctx) const -> decltype(ctx.out()) { - if (!opt) return detail::write(ctx.out(), none); + if (!opt) return detail::write_bytes(ctx.out(), "none"); auto out = ctx.out(); - out = detail::write(out, optional); + out = detail::write_bytes(out, "optional("); ctx.advance_to(out); out = underlying_.format(*opt, ctx); return detail::write(out, ')'); @@ -405,15 +400,6 @@ struct formatter, Char, std::enable_if_t<(std::is_void::value || is_formattable::value) && is_formattable::value>> { - private: - static constexpr basic_string_view expected_prefix = - detail::string_literal{}; - static constexpr basic_string_view unexpected_prefix = - detail::string_literal{}; - - public: FMT_CONSTEXPR auto parse(parse_context& ctx) -> const Char* { return ctx.begin(); } @@ -424,11 +410,11 @@ struct formatter, Char, auto out = ctx.out(); if (value.has_value()) { - out = detail::write(out, expected_prefix); + out = detail::write_bytes(out, "expected("); if constexpr (!std::is_void::value) out = detail::write_escaped_alternative(out, *value, ctx); } else { - out = detail::write(out, unexpected_prefix); + out = detail::write_bytes(out, "unexpected("); out = detail::write_escaped_alternative(out, value.error(), ctx); } *out++ = ')'; @@ -439,12 +425,6 @@ struct formatter, Char, template struct formatter, Char, std::enable_if_t::value>> { - private: - static constexpr basic_string_view unexpected_prefix = - detail::string_literal{}; - - public: FMT_CONSTEXPR auto parse(parse_context& ctx) -> const Char* { return ctx.begin(); } @@ -454,7 +434,7 @@ struct formatter, Char, -> decltype(ctx.out()) { auto out = ctx.out(); - out = detail::write(out, unexpected_prefix); + out = detail::write_bytes(out, "unexpected("); out = detail::write_escaped_alternative(out, value.error(), ctx); *out++ = ')'; @@ -490,12 +470,6 @@ template struct is_variant_like { }; template struct formatter { - private: - static constexpr basic_string_view monostate_str = - detail::string_literal{}; - - public: FMT_CONSTEXPR auto parse(parse_context& ctx) -> const Char* { return ctx.begin(); } @@ -503,7 +477,7 @@ template struct formatter { template FMT_CONSTEXPR auto format(const std::monostate&, FormatContext& ctx) const -> decltype(ctx.out()) { - return detail::write(ctx.out(), monostate_str); + return detail::write_bytes(ctx.out(), "monostate"); } }; @@ -512,15 +486,6 @@ struct formatter, detail::is_variant_formattable>>> { - private: - static constexpr basic_string_view variant_prefix = - detail::string_literal{}; - static constexpr basic_string_view valueless_str = - detail::string_literal{}; - - public: FMT_CONSTEXPR auto parse(parse_context& ctx) -> const Char* { return ctx.begin(); } @@ -530,7 +495,7 @@ struct formatter decltype(ctx.out()) { auto out = ctx.out(); - out = detail::write(out, variant_prefix); + out = detail::write_bytes(out, "variant("); FMT_TRY { std::visit( [&](const auto& v) { @@ -539,7 +504,7 @@ struct formatter(out, valueless_str); + out = detail::write_bytes(out, "valueless by exception"); } *out++ = ')'; return out; diff --git a/test/xchar-test.cc b/test/xchar-test.cc index f25f36e3..8de9fdef 100644 --- a/test/xchar-test.cc +++ b/test/xchar-test.cc @@ -469,8 +469,6 @@ TEST(std_test_xchar, variant) { TEST(std_test_xchar, expected) { # ifdef __cpp_lib_expected EXPECT_EQ(fmt::format(L"{}", std::expected{1}), L"expected(1)"); - EXPECT_EQ(fmt::format(L"{}", std::expected{std::unexpected(1)}), - L"unexpected(1)"); EXPECT_EQ(fmt::format(L"{}", std::unexpected(1)), L"unexpected(1)"); # endif }