@@ -111,12 +111,17 @@ void write_escaped_path(basic_memory_buffer<Char>& quoted,
111111#endif // FMT_CPP_LIB_FILESYSTEM
112112
113113#if defined(__cpp_lib_expected) || FMT_CPP_LIB_VARIANT
114- template <typename Char, typename OutputIt, typename T>
115- auto write_escaped_alternative (OutputIt out, const T& v) -> OutputIt {
114+
115+ template <typename Char, typename OutputIt, typename T, typename FormatContext>
116+ auto write_escaped_alternative (OutputIt out, const T& v, FormatContext& ctx)
117+ -> OutputIt {
116118 if constexpr (has_to_string_view<T>::value)
117119 return write_escaped_string<Char>(out, detail::to_string_view (v));
118120 if constexpr (std::is_same_v<T, Char>) return write_escaped_char (out, v);
119- return write<Char>(out, v);
121+
122+ formatter<std::remove_cv_t <T>, Char> underlying;
123+ maybe_set_debug_format (underlying, true );
124+ return underlying.format (v, ctx);
120125}
121126#endif
122127
@@ -382,18 +387,9 @@ struct formatter<std::optional<T>, Char,
382387 static constexpr basic_string_view<Char> none =
383388 detail::string_literal<Char, ' n' , ' o' , ' n' , ' e' >{};
384389
385- template <class U >
386- FMT_CONSTEXPR static auto maybe_set_debug_format (U& u, bool set)
387- -> decltype(u.set_debug_format(set)) {
388- u.set_debug_format (set);
389- }
390-
391- template <class U >
392- FMT_CONSTEXPR static void maybe_set_debug_format (U&, ...) {}
393-
394390 public:
395391 FMT_CONSTEXPR auto parse (parse_context<Char>& ctx) {
396- maybe_set_debug_format (underlying_, true );
392+ detail:: maybe_set_debug_format (underlying_, true );
397393 return underlying_.parse (ctx);
398394 }
399395
@@ -429,10 +425,10 @@ struct formatter<std::expected<T, E>, Char,
429425 if (value.has_value ()) {
430426 out = detail::write<Char>(out, " expected(" );
431427 if constexpr (!std::is_void<T>::value)
432- out = detail::write_escaped_alternative<Char>(out, *value);
428+ out = detail::write_escaped_alternative<Char>(out, *value, ctx );
433429 } else {
434430 out = detail::write<Char>(out, " unexpected(" );
435- out = detail::write_escaped_alternative<Char>(out, value.error ());
431+ out = detail::write_escaped_alternative<Char>(out, value.error (), ctx );
436432 }
437433 *out++ = ' )' ;
438434 return out;
@@ -496,7 +492,7 @@ struct formatter<Variant, Char,
496492 FMT_TRY {
497493 std::visit (
498494 [&](const auto & v) {
499- out = detail::write_escaped_alternative<Char>(out, v);
495+ out = detail::write_escaped_alternative<Char>(out, v, ctx );
500496 },
501497 value);
502498 }
0 commit comments