workaround MSVC bug, add test
This commit is contained in:
parent
03c29ded73
commit
2c271ac98c
@ -763,19 +763,29 @@ inline std::chrono::duration<Rep, std::milli> get_milliseconds(
|
||||
}
|
||||
|
||||
template <typename Char, typename Rep, typename OutputIt,
|
||||
FMT_ENABLE_IF(std::is_integral<Rep>::value)>
|
||||
FMT_ENABLE_IF(std::is_integral<Rep>::value && std::is_same<Char, char>::value)>
|
||||
OutputIt format_duration_value(OutputIt out, Rep val, int) {
|
||||
static FMT_CONSTEXPR_DECL const Char format[] = {'{', '}', 0};
|
||||
return format_to(out, FMT_STRING(format), val);
|
||||
return format_to(out, FMT_STRING("{}"), val);
|
||||
}
|
||||
|
||||
template <typename Char, typename Rep, typename OutputIt,
|
||||
FMT_ENABLE_IF(std::is_floating_point<Rep>::value)>
|
||||
FMT_ENABLE_IF(std::is_integral<Rep>::value && std::is_same<Char, wchar_t>::value)>
|
||||
OutputIt format_duration_value(OutputIt out, Rep val, int) {
|
||||
return format_to(out, FMT_STRING(L"{}"), val);
|
||||
}
|
||||
|
||||
template <typename Char, typename Rep, typename OutputIt,
|
||||
FMT_ENABLE_IF(std::is_floating_point<Rep>::value && std::is_same<Char, char>::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);
|
||||
static FMT_CONSTEXPR_DECL const Char fp_f[] = {'{', ':', 'g', '}', 0};
|
||||
return format_to(out, FMT_STRING(fp_f), val);
|
||||
if (precision >= 0) return format_to(out, FMT_STRING("{:.{}f}"), val, precision);
|
||||
return format_to(out, FMT_STRING("{:g}"), val);
|
||||
}
|
||||
|
||||
template <typename Char, typename Rep, typename OutputIt,
|
||||
FMT_ENABLE_IF(std::is_floating_point<Rep>::value && std::is_same<Char, wchar_t>::value)>
|
||||
OutputIt format_duration_value(OutputIt out, Rep val, int precision) {
|
||||
if (precision >= 0) return format_to(out, FMT_STRING("L{:.{}f}"), val, precision);
|
||||
return format_to(out, FMT_STRING("L{:g}"), val);
|
||||
}
|
||||
|
||||
template <typename Char, typename OutputIt>
|
||||
@ -791,14 +801,22 @@ OutputIt copy_unit(string_view unit, OutputIt out, wchar_t) {
|
||||
return std::copy(u.c_str(), u.c_str() + u.size(), out);
|
||||
}
|
||||
|
||||
template <typename Char, typename Period, typename OutputIt>
|
||||
template <typename Char, typename Period, typename OutputIt,
|
||||
FMT_ENABLE_IF(std::is_same<Char, char>::value)>
|
||||
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)) return format_to(out, FMT_STRING(num_f), Period::num);
|
||||
static FMT_CONSTEXPR_DECL const Char num_def_f[] = {'[', '{', '}', '/', '{', '}', ']', 's', 0};
|
||||
return format_to(out, FMT_STRING(num_def_f), Period::num, Period::den);
|
||||
if (const_check(Period::den == 1)) return format_to(out, FMT_STRING("[{}]s"), Period::num);
|
||||
return format_to(out, FMT_STRING("[{}/{}]s"), Period::num, Period::den);
|
||||
}
|
||||
|
||||
template <typename Char, typename Period, typename OutputIt,
|
||||
FMT_ENABLE_IF(std::is_same<Char, wchar_t>::value)>
|
||||
OutputIt format_duration_unit(OutputIt out) {
|
||||
if (const char* unit = get_units<Period>())
|
||||
return copy_unit(string_view(unit), out, Char());
|
||||
if (const_check(Period::den == 1)) return format_to(out, FMT_STRING(L"[{}]s"), Period::num);
|
||||
return format_to(out, FMT_STRING(L"[{}/{}]s"), Period::num, Period::den);
|
||||
}
|
||||
|
||||
template <typename FormatContext, typename OutputIt, typename Rep,
|
||||
|
||||
@ -1809,9 +1809,15 @@ constexpr char with_null[3] = {'{', '}', '\0'};
|
||||
constexpr char no_null[2] = {'{', '}'};
|
||||
|
||||
TEST(FormatTest, CompileTimeString) {
|
||||
static FMT_CONSTEXPR_DECL const char static_with_null[3] = {'{', '}', '\0'};
|
||||
static FMT_CONSTEXPR_DECL const wchar_t static_with_null_wide[3] = {'{', '}', '\0'};
|
||||
|
||||
EXPECT_EQ("42", fmt::format(FMT_STRING("{}"), 42));
|
||||
EXPECT_EQ(L"42", fmt::format(FMT_STRING(L"{}"), 42));
|
||||
EXPECT_EQ("foo", fmt::format(FMT_STRING("{}"), string_like()));
|
||||
EXPECT_EQ("42", fmt::format(FMT_STRING(static_with_null), 42));
|
||||
EXPECT_EQ(L"42", fmt::format(FMT_STRING(static_with_null_wide), 42));
|
||||
|
||||
(void)with_null;
|
||||
(void)no_null;
|
||||
#if __cplusplus >= 201703L
|
||||
|
||||
Loading…
Reference in New Issue
Block a user