Skip to content

Commit e814b5f

Browse files
committed
Reduce template parametrization
1 parent ed0d216 commit e814b5f

File tree

1 file changed

+15
-22
lines changed

1 file changed

+15
-22
lines changed

include/fmt/chrono.h

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1694,10 +1694,9 @@ class get_locale {
16941694
}
16951695
};
16961696

1697-
template <typename FormatContext, typename OutputIt, typename Rep,
1698-
typename Period>
1697+
template <typename Char, typename OutputIt, typename Rep, typename Period>
16991698
struct duration_formatter {
1700-
FormatContext& context;
1699+
locale_ref locale;
17011700
OutputIt out;
17021701
int precision;
17031702
bool localized = false;
@@ -1711,15 +1710,11 @@ struct duration_formatter {
17111710
using milliseconds = std::chrono::duration<rep, std::milli>;
17121711
bool negative;
17131712

1714-
using char_type = typename FormatContext::char_type;
1715-
using tm_writer_type = tm_writer<OutputIt, char_type>;
1713+
using tm_writer_type = tm_writer<OutputIt, Char>;
17161714

1717-
duration_formatter(FormatContext& ctx, OutputIt o,
1715+
duration_formatter(locale_ref loc, OutputIt o,
17181716
std::chrono::duration<Rep, Period> d)
1719-
: context(ctx),
1720-
out(o),
1721-
val(static_cast<rep>(d.count())),
1722-
negative(false) {
1717+
: locale(loc), out(o), val(static_cast<rep>(d.count())), negative(false) {
17231718
if (d.count() < 0) {
17241719
val = 0 - val;
17251720
negative = true;
@@ -1784,22 +1779,22 @@ struct duration_formatter {
17841779
if (width > num_digits) {
17851780
out = detail::write_padding(out, pad, width - num_digits);
17861781
}
1787-
out = format_decimal<char_type>(out, n, num_digits);
1782+
out = format_decimal<Char>(out, n, num_digits);
17881783
}
17891784

17901785
void write_nan() { std::copy_n("nan", 3, out); }
17911786

17921787
template <typename Callback, typename... Args>
17931788
void format_tm(const tm& time, Callback cb, Args... args) {
17941789
if (isnan(val)) return write_nan();
1795-
get_locale loc(localized, context.locale());
1790+
get_locale loc(localized, locale);
17961791
auto w = tm_writer_type(loc, out, time);
17971792
(w.*cb)(args...);
17981793
out = w.out();
17991794
}
18001795

1801-
void on_text(const char_type* begin, const char_type* end) {
1802-
copy<char_type>(begin, end, out);
1796+
void on_text(const Char* begin, const Char* end) {
1797+
copy<Char>(begin, end, out);
18031798
}
18041799

18051800
// These are not implemented because durations don't have date information.
@@ -1871,10 +1866,10 @@ struct duration_formatter {
18711866
if (negative) *out++ = '-';
18721867
if (buf.size() < 2 || buf[1] == '.')
18731868
out = detail::write_padding(out, pad);
1874-
out = copy<char_type>(buf.begin(), buf.end(), out);
1869+
out = copy<Char>(buf.begin(), buf.end(), out);
18751870
} else {
18761871
write(second(), 2, pad);
1877-
write_fractional_seconds<char_type>(
1872+
write_fractional_seconds<Char>(
18781873
out, std::chrono::duration<rep, Period>(val), precision);
18791874
}
18801875
return;
@@ -1916,12 +1911,10 @@ struct duration_formatter {
19161911
void on_duration_value() {
19171912
if (handle_nan_inf()) return;
19181913
write_sign();
1919-
out = format_duration_value<char_type>(out, val, precision);
1914+
out = format_duration_value<Char>(out, val, precision);
19201915
}
19211916

1922-
void on_duration_unit() {
1923-
out = format_duration_unit<char_type, Period>(out);
1924-
}
1917+
void on_duration_unit() { out = format_duration_unit<Char, Period>(out); }
19251918
};
19261919

19271920
} // namespace detail
@@ -2181,8 +2174,8 @@ struct formatter<std::chrono::duration<Rep, Period>, Char> {
21812174
detail::format_duration_unit<Char, Period>(out);
21822175
} else {
21832176
using duration_formatter =
2184-
detail::duration_formatter<FormatContext, decltype(out), Rep, Period>;
2185-
auto f = duration_formatter(ctx, out, d);
2177+
detail::duration_formatter<Char, decltype(out), Rep, Period>;
2178+
auto f = duration_formatter(ctx.locale(), out, d);
21862179
f.precision = precision;
21872180
f.localized = localized_;
21882181
detail::parse_chrono_format(begin, end, f);

0 commit comments

Comments
 (0)