diff --git a/include/fmt/format.h b/include/fmt/format.h index 0d9dd0e6..ed4ef1a2 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -1561,6 +1561,22 @@ template struct int_writer { } }; +template +OutputIt write_nonfinite(OutputIt out, bool isinf, + const basic_format_specs& specs, + const float_specs& fspecs) { + auto str = + isinf ? (fspecs.upper ? "INF" : "inf") : (fspecs.upper ? "NAN" : "nan"); + constexpr size_t str_size = 3; + auto sign = fspecs.sign; + auto size = str_size + (sign ? 1 : 0); + using iterator = remove_reference_t; + return write_padded(out, specs, size, [=](iterator it) { + if (sign) *it++ = static_cast(data::signs[sign]); + return copy_str(str, str + str_size, it); + }); +} + template OutputIt write_ptr(OutputIt out, UIntPtr value, const basic_format_specs* specs) { @@ -1648,15 +1664,7 @@ template class basic_writer { } if (!std::isfinite(value)) { - auto str = std::isinf(value) ? (fspecs.upper ? "INF" : "inf") - : (fspecs.upper ? "NAN" : "nan"); - constexpr size_t str_size = 3; - auto sign = fspecs.sign; - auto size = str_size + (sign ? 1 : 0); - out_ = write_padded(out_, specs, size, [=](reserve_iterator it) { - if (sign) *it++ = static_cast(data::signs[sign]); - return copy_str(str, str + str_size, it); - }); + out_ = write_nonfinite(out_, std::isinf(value), specs, fspecs); return; }