diff --git a/include/fmt/color.h b/include/fmt/color.h index 0c25bf4f..e5a487bf 100644 --- a/include/fmt/color.h +++ b/include/fmt/color.h @@ -492,11 +492,8 @@ template inline void reset_color(buffer& buffer) { buffer.append(reset_color.begin(), reset_color.end()); } -template struct styled_arg { - FMT_CONSTEXPR styled_arg(const Arg& format_argument, text_style format_style) - : argument(format_argument), style(format_style) {} - - const Arg& argument; +template struct styled_arg { + const T& value; text_style style; }; @@ -638,13 +635,13 @@ inline auto format_to(OutputIt out, const text_style& ts, const S& format_str, fmt::make_format_args>>(args...)); } -template -struct formatter, Char> : formatter { +template +struct formatter, Char> : formatter { template - auto format(const detail::styled_arg& arg, FormatContext& ctx) const + auto format(const detail::styled_arg& arg, FormatContext& ctx) const -> decltype(ctx.out()) { const auto& ts = arg.style; - const auto& value = arg.argument; + const auto& value = arg.value; auto out = ctx.out(); using detail::get_buffer; @@ -668,7 +665,7 @@ struct formatter, Char> : formatter { detail::make_background_color(ts.get_background()); buf.append(background.begin(), background.end()); } - out = formatter::format(value, ctx); + out = formatter::format(value, ctx); if (has_style) detail::reset_color(buf); return out; } @@ -685,10 +682,10 @@ struct formatter, Char> : formatter { fmt::styled(1.23, fmt::fg(fmt::colors::green) | fmt::bg(fmt::color::blue))); \endrst */ -template -FMT_CONSTEXPR auto styled(const Arg& arg, text_style ts = {}) - -> detail::styled_arg> { - return detail::styled_arg>(arg, ts); +template +FMT_CONSTEXPR auto styled(const T& value, text_style ts = {}) + -> detail::styled_arg> { + return detail::styled_arg>{value, ts}; } /** @@ -701,10 +698,10 @@ FMT_CONSTEXPR auto styled(const Arg& arg, text_style ts = {}) fmt::print("Elapsed time: {s:.2f} seconds", fmt::styled(1.23, fmt::colors::green)); \endrst */ -template -FMT_CONSTEXPR auto styled(const Arg& arg, detail::color_type color) - -> detail::styled_arg> { - return detail::styled_arg>(arg, fg(color)); +template +FMT_CONSTEXPR auto styled(const T& value, detail::color_type color) + -> detail::styled_arg> { + return detail::styled_arg>{value, fg(color)}; } /** @@ -717,10 +714,10 @@ FMT_CONSTEXPR auto styled(const Arg& arg, detail::color_type color) fmt::print("Elapsed time: {s:.2f} seconds", fmt::styled(1.23, fmt::emphasis::italic)); \endrst */ -template -FMT_CONSTEXPR auto styled(const Arg& arg, emphasis em) - -> detail::styled_arg> { - return detail::styled_arg>(arg, text_style(em)); +template +FMT_CONSTEXPR auto styled(const T& value, emphasis em) + -> detail::styled_arg> { + return detail::styled_arg>{value, text_style(em)}; } FMT_MODULE_EXPORT_END