diff --git a/include/fmt/format.h b/include/fmt/format.h index 3734b419..99b24427 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -2053,7 +2053,16 @@ auto write_int(OutputIt out, UInt value, unsigned prefix, }); } -// Writes localized value. +template ::value)> +auto make_loc_value(T value) -> basic_format_arg> { + return make_arg>(value); +} +template ::value)> +auto make_loc_value(T) -> basic_format_arg> { + return {}; +} + +// Writes a localized value. FMT_API auto write_loc(appender out, basic_format_arg value, const format_specs& specs, locale_ref loc) -> bool; @@ -2182,7 +2191,7 @@ FMT_CONSTEXPR FMT_INLINE auto write(OutputIt out, T value, const basic_format_specs& specs, locale_ref loc) -> OutputIt { if (specs.localized && - write_loc(out, make_arg>(value), specs, loc)) { + write_loc(out, make_loc_value(value), specs, loc)) { return out; } return write_int_noinline(out, make_write_int_arg(value, specs.sign), specs, @@ -2197,7 +2206,7 @@ FMT_CONSTEXPR FMT_INLINE auto write(OutputIt out, T value, const basic_format_specs& specs, locale_ref loc) -> OutputIt { if (specs.localized && - write_loc(out, make_arg>(value), specs, loc)) { + write_loc(out, make_loc_value(value), specs, loc)) { return out; } return write_int(out, make_write_int_arg(value, specs.sign), specs, loc); @@ -3251,13 +3260,10 @@ FMT_CONSTEXPR20 auto format_float(Float value, int precision, float_specs specs, } return exp; } - -template ::value)> -FMT_CONSTEXPR20 auto write(OutputIt out, T value, - basic_format_specs specs, locale_ref loc = {}) +template +FMT_CONSTEXPR20 auto write_float(OutputIt out, T value, + basic_format_specs specs, locale_ref loc) -> OutputIt { - if (const_check(!is_supported_floating_point(value))) return out; float_specs fspecs = parse_float_type_spec(specs); fspecs.sign = specs.sign; if (detail::signbit(value)) { // value < 0 is false for NaN so use signbit. @@ -3303,6 +3309,19 @@ FMT_CONSTEXPR20 auto write(OutputIt out, T value, return write_float(out, f, specs, fspecs, loc); } +template ::value)> +FMT_CONSTEXPR20 auto write(OutputIt out, T value, + basic_format_specs specs, locale_ref loc = {}) + -> OutputIt { + if (const_check(!is_supported_floating_point(value))) return out; + if (specs.localized && + write_loc(out, make_loc_value(value), specs, loc)) { + return out; + } + return write_float(out, value, specs, loc); +} + template ::value)> FMT_CONSTEXPR20 auto write(OutputIt out, T value) -> OutputIt {