From b7f240a0df69a0c680d9c18586c22b2636383fbe Mon Sep 17 00:00:00 2001 From: Alberto Aguirre Date: Thu, 19 Mar 2020 18:18:41 -0500 Subject: [PATCH] Add is_supported_floating_point constexpr function --- include/fmt/format.h | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/include/fmt/format.h b/include/fmt/format.h index c698aa04..b2743d21 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -726,6 +726,13 @@ FMT_CONSTEXPR bool is_negative(T) { return false; } +template ::value)> +FMT_CONSTEXPR bool is_supported_floating_point(T) { + return (std::is_same::value && FMT_USE_FLOAT) || + (std::is_same::value && FMT_USE_DOUBLE) || + (std::is_same::value && FMT_USE_LONG_DOUBLE); +} + // Smallest of uint32_t, uint64_t, uint128_t that is large enough to // represent all values of T. template @@ -1687,10 +1694,7 @@ template class basic_writer { template ::value)> void write(T value, format_specs specs = {}) { - if (const_check( - (std::is_same::value && !FMT_USE_FLOAT) || - (std::is_same::value && !FMT_USE_DOUBLE) || - (std::is_same::value && !FMT_USE_LONG_DOUBLE))) { + if (const_check(!is_supported_floating_point(value))) { return; } float_specs fspecs = parse_float_type_spec(specs); @@ -1891,11 +1895,8 @@ class arg_formatter_base { template ::value)> iterator operator()(T value) { - if (const_check( - (std::is_same::value && !FMT_USE_FLOAT) || - (std::is_same::value && !FMT_USE_DOUBLE) || - (std::is_same::value && !FMT_USE_LONG_DOUBLE))) { - FMT_ASSERT(false, "unsupported float argument"); + if (const_check(!is_supported_floating_point(value))) { + FMT_ASSERT(false, "unsupported float argument type"); return out(); } writer_.write(value, specs_ ? *specs_ : format_specs());