From f2ed03b9191a629d728f9ee47e4fd81f9dd1931c Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Tue, 28 Apr 2020 06:19:29 -0700 Subject: [PATCH] Fix a warning (#1649) --- include/fmt/chrono.h | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/include/fmt/chrono.h b/include/fmt/chrono.h index 2aed3143..29f7a250 100644 --- a/include/fmt/chrono.h +++ b/include/fmt/chrono.h @@ -768,19 +768,23 @@ OutputIt format_duration_value(OutputIt out, Rep val, int precision) { return format_to(out, std::is_floating_point::value ? fp_f : format, val); } +template +OutputIt copy_unit(string_view unit, OutputIt out, Char) { + return std::copy(unit.begin(), unit.end(), out); +} + +template +OutputIt copy_unit(string_view unit, OutputIt out, wchar_t) { + // This works when wchar_t is UTF-32 because units only contain characters + // that have the same representation in UTF-16 and UTF-32. + utf8_to_utf16 u(unit); + return std::copy(u.c_str(), u.c_str() + u.size(), out); +} template OutputIt format_duration_unit(OutputIt out) { - if (const char* unit = get_units()) { - string_view s(unit); - if (const_check(std::is_same())) { - // This works when wchar_t is UTF-32 because units only contain code - // points that have the same values in UTF-16 and UTF-32. - utf8_to_utf16 u(s); - return std::copy(u.c_str(), u.c_str() + u.size(), out); - } - return std::copy(s.begin(), s.end(), out); - } + if (const char* unit = get_units()) + return copy_unit(string_view(unit), out, Char()); const Char num_f[] = {'[', '{', '}', ']', 's', 0}; if (Period::den == 1) return format_to(out, num_f, Period::num); const Char num_def_f[] = {'[', '{', '}', '/', '{', '}', ']', 's', 0};