From c3c9a69acebfbf36cda57a8e1902ec5a4c5f8072 Mon Sep 17 00:00:00 2001 From: Alberto Aguirre Date: Thu, 19 Mar 2020 16:33:51 -0500 Subject: [PATCH] Avoid conditional macros to disable float support --- include/fmt/core.h | 12 ---------- include/fmt/format.h | 54 +++++++++++++++++++++----------------------- 2 files changed, 26 insertions(+), 40 deletions(-) diff --git a/include/fmt/core.h b/include/fmt/core.h index 4bf6d310..620719f7 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -1095,23 +1095,11 @@ FMT_CONSTEXPR auto visit_format_arg(Visitor&& vis, case internal::type::char_type: return vis(arg.value_.char_value); case internal::type::float_type: -#if FMT_USE_FLOAT return vis(arg.value_.float_value); -#else - break; -#endif case internal::type::double_type: -#if FMT_USE_DOUBLE return vis(arg.value_.double_value); -#else - break; -#endif case internal::type::long_double_type: -#if FMT_USE_LONG_DOUBLE return vis(arg.value_.long_double_value); -#else - break; -#endif case internal::type::cstring_type: return vis(arg.value_.string.data); case internal::type::string_type: diff --git a/include/fmt/format.h b/include/fmt/format.h index f1f8aed8..c698aa04 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -1685,9 +1685,14 @@ template class basic_writer { handle_int_type_spec(spec.type, int_writer(*this, value, spec)); } -#if FMT_USE_FLOAT || FMT_USE_DOUBLE || FMT_USE_LONG_DOUBLE template ::value)> - void write_float(T value, format_specs specs = {}) { + 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))) { + return; + } float_specs fspecs = parse_float_type_spec(specs); fspecs.sign = specs.sign; if (std::signbit(value)) { // value < 0 is false for NaN so use signbit. @@ -1744,17 +1749,6 @@ template class basic_writer { static_cast(buffer.size()), exp, fspecs, point)); } -#endif - -#if FMT_USE_FLOAT - void write(float value, format_specs specs = {}) { write_float(value, specs); } -#endif -#if FMT_USE_DOUBLE - void write(double value, format_specs specs = {}) { write_float(value, specs); } -#endif -#if FMT_USE_LONG_DOUBLE - void write(long double value, format_specs specs = {}) { write_float(value, specs); } -#endif void write(char value) { auto&& it = reserve(1); @@ -1897,6 +1891,13 @@ 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"); + return out(); + } writer_.write(value, specs_ ? *specs_ : format_specs()); return out(); } @@ -2937,25 +2938,22 @@ struct formatter(specs_.type, eh)); break; case internal::type::float_type: -#if FMT_USE_FLOAT - internal::parse_float_type_spec(specs_, eh); -#else - FMT_ASSERT(false, "float support disabled"); -#endif + if (internal::const_check(FMT_USE_FLOAT)) + internal::parse_float_type_spec(specs_, eh); + else + FMT_ASSERT(false, "float support disabled"); break; case internal::type::double_type: -#if FMT_USE_DOUBLE - internal::parse_float_type_spec(specs_, eh); -#else - FMT_ASSERT(false, "double support disabled"); -#endif + if (internal::const_check(FMT_USE_DOUBLE)) + internal::parse_float_type_spec(specs_, eh); + else + FMT_ASSERT(false, "double support disabled"); break; case internal::type::long_double_type: -#if FMT_USE_LONG_DOUBLE - internal::parse_float_type_spec(specs_, eh); -#else - FMT_ASSERT(false, "long double support disabled"); -#endif + if (internal::const_check(FMT_USE_LONG_DOUBLE)) + internal::parse_float_type_spec(specs_, eh); + else + FMT_ASSERT(false, "long double support disabled"); break; case internal::type::cstring_type: internal::handle_cstring_type_spec(