Skip to content

Commit

Permalink
workaround MSVC bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Walter Gray committed Nov 30, 2020
1 parent 761822a commit 930c554
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions include/fmt/chrono.h
Original file line number Diff line number Diff line change
Expand Up @@ -769,17 +769,36 @@ template <typename Char, typename Rep, typename OutputIt,
FMT_ENABLE_IF(std::is_integral<Rep>::value)>
OutputIt format_duration_value(OutputIt out, Rep val, int) {
static FMT_CONSTEXPR_DECL const Char format[] = {'{', '}', 0};

#if defined(FMT_MSC_VER) && FMT_MSC_VER < 1928
return vformat_to(out, to_string_view(format),
make_format_args<buffer_context<Char>>(val));
#else
return format_to(out, FMT_STRING(format), val);
#endif
}

template <typename Char, typename Rep, typename OutputIt,
FMT_ENABLE_IF(std::is_floating_point<Rep>::value)>
OutputIt format_duration_value(OutputIt out, Rep val, int precision) {
static FMT_CONSTEXPR_DECL const Char pr_f[] = {'{', ':', '.', '{',
'}', 'f', '}', 0};
if (precision >= 0) return format_to(out, FMT_STRING(pr_f), val, precision);
if (precision >= 0) {
#if defined(FMT_MSC_VER) && FMT_MSC_VER < 1928
return vformat_to(out, to_string_view(pr_f),
make_format_args<buffer_context<Char>>(val, precision));
#else
return format_to(out, FMT_STRING(pr_f), val, precision);
#endif
}
static FMT_CONSTEXPR_DECL const Char fp_f[] = {'{', ':', 'g', '}', 0};

#if defined(FMT_MSC_VER) && FMT_MSC_VER < 1928
return vformat_to(out, to_string_view(fp_f),
make_format_args<buffer_context<Char>>(val));
#else
return format_to(out, FMT_STRING(fp_f), val);
#endif
}

template <typename Char, typename OutputIt>
Expand All @@ -800,11 +819,23 @@ OutputIt format_duration_unit(OutputIt out) {
if (const char* unit = get_units<Period>())
return copy_unit(string_view(unit), out, Char());
static FMT_CONSTEXPR_DECL const Char num_f[] = {'[', '{', '}', ']', 's', 0};
if (const_check(Period::den == 1))
if (const_check(Period::den == 1)) {
#if defined(FMT_MSC_VER) && FMT_MSC_VER < 1928
return vformat_to(out, to_string_view(num_f),
make_format_args<buffer_context<Char>>(Period::num));
#else
return format_to(out, FMT_STRING(num_f), Period::num);
#endif
}
static FMT_CONSTEXPR_DECL const Char num_def_f[] = {'[', '{', '}', '/', '{',
'}', ']', 's', 0};
#if defined(FMT_MSC_VER) && FMT_MSC_VER < 1928
return vformat_to(
out, to_string_view(num_def_f),
make_format_args<buffer_context<Char>>(Period::num, Period::den));
#else
return format_to(out, FMT_STRING(num_def_f), Period::num, Period::den);
#endif
}

template <typename FormatContext, typename OutputIt, typename Rep,
Expand Down

0 comments on commit 930c554

Please sign in to comment.