Remove redundant constructor for styled_arg

This commit is contained in:
rbrugo 2022-03-08 00:11:22 +01:00
parent d9af1566fc
commit ad95044f25

View File

@ -492,11 +492,8 @@ template <typename Char> inline void reset_color(buffer<Char>& buffer) {
buffer.append(reset_color.begin(), reset_color.end()); buffer.append(reset_color.begin(), reset_color.end());
} }
template <typename Arg> struct styled_arg { template <typename T> struct styled_arg {
FMT_CONSTEXPR styled_arg(const Arg& format_argument, text_style format_style) const T& value;
: argument(format_argument), style(format_style) {}
const Arg& argument;
text_style style; 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<buffer_context<char_t<S>>>(args...)); fmt::make_format_args<buffer_context<char_t<S>>>(args...));
} }
template <typename Arg, typename Char> template <typename T, typename Char>
struct formatter<detail::styled_arg<Arg>, Char> : formatter<Arg, Char> { struct formatter<detail::styled_arg<T>, Char> : formatter<T, Char> {
template <typename FormatContext> template <typename FormatContext>
auto format(const detail::styled_arg<Arg>& arg, FormatContext& ctx) const auto format(const detail::styled_arg<T>& arg, FormatContext& ctx) const
-> decltype(ctx.out()) { -> decltype(ctx.out()) {
const auto& ts = arg.style; const auto& ts = arg.style;
const auto& value = arg.argument; const auto& value = arg.value;
auto out = ctx.out(); auto out = ctx.out();
using detail::get_buffer; using detail::get_buffer;
@ -668,7 +665,7 @@ struct formatter<detail::styled_arg<Arg>, Char> : formatter<Arg, Char> {
detail::make_background_color<Char>(ts.get_background()); detail::make_background_color<Char>(ts.get_background());
buf.append(background.begin(), background.end()); buf.append(background.begin(), background.end());
} }
out = formatter<Arg, Char>::format(value, ctx); out = formatter<T, Char>::format(value, ctx);
if (has_style) detail::reset_color<Char>(buf); if (has_style) detail::reset_color<Char>(buf);
return out; return out;
} }
@ -685,10 +682,10 @@ struct formatter<detail::styled_arg<Arg>, Char> : formatter<Arg, Char> {
fmt::styled(1.23, fmt::fg(fmt::colors::green) | fmt::styled(1.23, fmt::fg(fmt::colors::green) |
fmt::bg(fmt::color::blue))); \endrst fmt::bg(fmt::color::blue))); \endrst
*/ */
template <typename Arg> template <typename T>
FMT_CONSTEXPR auto styled(const Arg& arg, text_style ts = {}) FMT_CONSTEXPR auto styled(const T& value, text_style ts = {})
-> detail::styled_arg<remove_cvref_t<Arg>> { -> detail::styled_arg<remove_cvref_t<T>> {
return detail::styled_arg<remove_cvref_t<Arg>>(arg, ts); return detail::styled_arg<remove_cvref_t<T>>{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::print("Elapsed time: {s:.2f} seconds", fmt::styled(1.23,
fmt::colors::green)); \endrst fmt::colors::green)); \endrst
*/ */
template <typename Arg> template <typename T>
FMT_CONSTEXPR auto styled(const Arg& arg, detail::color_type color) FMT_CONSTEXPR auto styled(const T& value, detail::color_type color)
-> detail::styled_arg<remove_cvref_t<Arg>> { -> detail::styled_arg<remove_cvref_t<T>> {
return detail::styled_arg<remove_cvref_t<Arg>>(arg, fg(color)); return detail::styled_arg<remove_cvref_t<T>>{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::print("Elapsed time: {s:.2f} seconds", fmt::styled(1.23,
fmt::emphasis::italic)); \endrst fmt::emphasis::italic)); \endrst
*/ */
template <typename Arg> template <typename T>
FMT_CONSTEXPR auto styled(const Arg& arg, emphasis em) FMT_CONSTEXPR auto styled(const T& value, emphasis em)
-> detail::styled_arg<remove_cvref_t<Arg>> { -> detail::styled_arg<remove_cvref_t<T>> {
return detail::styled_arg<remove_cvref_t<Arg>>(arg, text_style(em)); return detail::styled_arg<remove_cvref_t<T>>{value, text_style(em)};
} }
FMT_MODULE_EXPORT_END FMT_MODULE_EXPORT_END