Fix formatting

This commit is contained in:
Victor Zverovich 2020-12-24 06:54:33 -08:00
parent 4fa4c9248f
commit 1256541d7a
3 changed files with 6 additions and 18 deletions

View File

@ -783,7 +783,7 @@ OutputIt format_duration_value(OutputIt out, Rep val, int) {
template <typename Char, typename Rep, typename OutputIt, template <typename Char, typename Rep, typename OutputIt,
FMT_ENABLE_IF(std::is_floating_point<Rep>::value)> FMT_ENABLE_IF(std::is_floating_point<Rep>::value)>
OutputIt format_duration_value(OutputIt out, Rep val, int precision) { OutputIt format_duration_value(OutputIt out, Rep val, int precision) {
basic_format_specs<Char> specs; auto specs = basic_format_specs<Char>();
specs.precision = precision; specs.precision = precision;
specs.type = precision > 0 ? 'f' : 'g'; specs.type = precision > 0 ? 'f' : 'g';
return write<Char>(out, val, specs); return write<Char>(out, val, specs);
@ -806,15 +806,12 @@ template <typename Char, typename Period, typename OutputIt>
OutputIt format_duration_unit(OutputIt out) { OutputIt format_duration_unit(OutputIt out) {
if (const char* unit = get_units<Period>()) if (const char* unit = get_units<Period>())
return copy_unit(string_view(unit), out, Char()); return copy_unit(string_view(unit), out, Char());
*out++ = '['; *out++ = '[';
out = write<Char>(out, Period::num); out = write<Char>(out, Period::num);
if (const_check(Period::den != 1)) { if (const_check(Period::den != 1)) {
*out++ = '/'; *out++ = '/';
out = write<Char>(out, Period::den); out = write<Char>(out, Period::den);
} }
*out++ = ']'; *out++ = ']';
*out++ = 's'; *out++ = 's';
return out; return out;

View File

@ -287,14 +287,10 @@ struct formatter<TupleT, Char, enable_if_t<fmt::is_tuple_like<TupleT>::value>> {
// C++11 generic lambda for format() // C++11 generic lambda for format()
template <typename FormatContext> struct format_each { template <typename FormatContext> struct format_each {
template <typename T> void operator()(const T& v) { template <typename T> void operator()(const T& v) {
if (i > 0) { if (i > 0) out = write_delimiter(out);
out = write_delimiter(out);
}
out = detail::write_range_entry<Char>(out, v); out = detail::write_range_entry<Char>(out, v);
++i; ++i;
} }
formatting_tuple<Char>& formatting; formatting_tuple<Char>& formatting;
size_t& i; size_t& i;
typename std::add_lvalue_reference<decltype( typename std::add_lvalue_reference<decltype(
@ -356,12 +352,8 @@ struct formatter<
auto it = view.begin(); auto it = view.begin();
auto end = view.end(); auto end = view.end();
for (; it != end; ++it) { for (; it != end; ++it) {
if (i > 0) { if (i > 0) out = detail::write_delimiter(out);
out = detail::write_delimiter(out);
}
out = detail::write_range_entry<Char>(out, *it); out = detail::write_range_entry<Char>(out, *it);
if (++i > formatting.range_length_limit) { if (++i > formatting.range_length_limit) {
out = format_to(out, FMT_STRING("{}"), " ... <other elements>"); out = format_to(out, FMT_STRING("{}"), " ... <other elements>");
break; break;

View File

@ -107,12 +107,11 @@ add_fmt_test(ranges-test)
add_fmt_test(scan-test) add_fmt_test(scan-test)
if (NOT MSVC) if (NOT MSVC)
# FMT_ENFORCE_COMPILE_STRING not supported under MSVC # FMT_ENFORCE_COMPILE_STRING is not supported under MSVC due to compiler bugs.
# See https://developercommunity.visualstudio.com/content/problem/1277597/internal-compiler-c0001-error-on-complex-nested-la.html
add_fmt_test(enforce-compile-string-test) add_fmt_test(enforce-compile-string-test)
target_compile_definitions(enforce-compile-string-test PRIVATE target_compile_definitions(enforce-compile-string-test PRIVATE
"-DFMT_ENFORCE_COMPILE_STRING") -DFMT_ENFORCE_COMPILE_STRING)
endif() endif ()
if (NOT DEFINED MSVC_STATIC_RUNTIME AND MSVC) if (NOT DEFINED MSVC_STATIC_RUNTIME AND MSVC)
foreach (flag_var foreach (flag_var