Avoid conditional macros to disable float support
This commit is contained in:
parent
a15c81e5ff
commit
c3c9a69ace
@ -1095,23 +1095,11 @@ FMT_CONSTEXPR auto visit_format_arg(Visitor&& vis,
|
|||||||
case internal::type::char_type:
|
case internal::type::char_type:
|
||||||
return vis(arg.value_.char_value);
|
return vis(arg.value_.char_value);
|
||||||
case internal::type::float_type:
|
case internal::type::float_type:
|
||||||
#if FMT_USE_FLOAT
|
|
||||||
return vis(arg.value_.float_value);
|
return vis(arg.value_.float_value);
|
||||||
#else
|
|
||||||
break;
|
|
||||||
#endif
|
|
||||||
case internal::type::double_type:
|
case internal::type::double_type:
|
||||||
#if FMT_USE_DOUBLE
|
|
||||||
return vis(arg.value_.double_value);
|
return vis(arg.value_.double_value);
|
||||||
#else
|
|
||||||
break;
|
|
||||||
#endif
|
|
||||||
case internal::type::long_double_type:
|
case internal::type::long_double_type:
|
||||||
#if FMT_USE_LONG_DOUBLE
|
|
||||||
return vis(arg.value_.long_double_value);
|
return vis(arg.value_.long_double_value);
|
||||||
#else
|
|
||||||
break;
|
|
||||||
#endif
|
|
||||||
case internal::type::cstring_type:
|
case internal::type::cstring_type:
|
||||||
return vis(arg.value_.string.data);
|
return vis(arg.value_.string.data);
|
||||||
case internal::type::string_type:
|
case internal::type::string_type:
|
||||||
|
|||||||
@ -1685,9 +1685,14 @@ template <typename Range> class basic_writer {
|
|||||||
handle_int_type_spec(spec.type, int_writer<T, Spec>(*this, value, spec));
|
handle_int_type_spec(spec.type, int_writer<T, Spec>(*this, value, spec));
|
||||||
}
|
}
|
||||||
|
|
||||||
#if FMT_USE_FLOAT || FMT_USE_DOUBLE || FMT_USE_LONG_DOUBLE
|
|
||||||
template <typename T, FMT_ENABLE_IF(std::is_floating_point<T>::value)>
|
template <typename T, FMT_ENABLE_IF(std::is_floating_point<T>::value)>
|
||||||
void write_float(T value, format_specs specs = {}) {
|
void write(T value, format_specs specs = {}) {
|
||||||
|
if (const_check(
|
||||||
|
(std::is_same<T, float>::value && !FMT_USE_FLOAT) ||
|
||||||
|
(std::is_same<T, double>::value && !FMT_USE_DOUBLE) ||
|
||||||
|
(std::is_same<T, long double>::value && !FMT_USE_LONG_DOUBLE))) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
float_specs fspecs = parse_float_type_spec(specs);
|
float_specs fspecs = parse_float_type_spec(specs);
|
||||||
fspecs.sign = specs.sign;
|
fspecs.sign = specs.sign;
|
||||||
if (std::signbit(value)) { // value < 0 is false for NaN so use signbit.
|
if (std::signbit(value)) { // value < 0 is false for NaN so use signbit.
|
||||||
@ -1744,17 +1749,6 @@ template <typename Range> class basic_writer {
|
|||||||
static_cast<int>(buffer.size()),
|
static_cast<int>(buffer.size()),
|
||||||
exp, fspecs, point));
|
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) {
|
void write(char value) {
|
||||||
auto&& it = reserve(1);
|
auto&& it = reserve(1);
|
||||||
@ -1897,6 +1891,13 @@ class arg_formatter_base {
|
|||||||
|
|
||||||
template <typename T, FMT_ENABLE_IF(std::is_floating_point<T>::value)>
|
template <typename T, FMT_ENABLE_IF(std::is_floating_point<T>::value)>
|
||||||
iterator operator()(T value) {
|
iterator operator()(T value) {
|
||||||
|
if (const_check(
|
||||||
|
(std::is_same<T, float>::value && !FMT_USE_FLOAT) ||
|
||||||
|
(std::is_same<T, double>::value && !FMT_USE_DOUBLE) ||
|
||||||
|
(std::is_same<T, long double>::value && !FMT_USE_LONG_DOUBLE))) {
|
||||||
|
FMT_ASSERT(false, "unsupported float argument");
|
||||||
|
return out();
|
||||||
|
}
|
||||||
writer_.write(value, specs_ ? *specs_ : format_specs());
|
writer_.write(value, specs_ ? *specs_ : format_specs());
|
||||||
return out();
|
return out();
|
||||||
}
|
}
|
||||||
@ -2937,25 +2938,22 @@ struct formatter<T, Char,
|
|||||||
&specs_, internal::char_specs_checker<decltype(eh)>(specs_.type, eh));
|
&specs_, internal::char_specs_checker<decltype(eh)>(specs_.type, eh));
|
||||||
break;
|
break;
|
||||||
case internal::type::float_type:
|
case internal::type::float_type:
|
||||||
#if FMT_USE_FLOAT
|
if (internal::const_check(FMT_USE_FLOAT))
|
||||||
internal::parse_float_type_spec(specs_, eh);
|
internal::parse_float_type_spec(specs_, eh);
|
||||||
#else
|
else
|
||||||
FMT_ASSERT(false, "float support disabled");
|
FMT_ASSERT(false, "float support disabled");
|
||||||
#endif
|
|
||||||
break;
|
break;
|
||||||
case internal::type::double_type:
|
case internal::type::double_type:
|
||||||
#if FMT_USE_DOUBLE
|
if (internal::const_check(FMT_USE_DOUBLE))
|
||||||
internal::parse_float_type_spec(specs_, eh);
|
internal::parse_float_type_spec(specs_, eh);
|
||||||
#else
|
else
|
||||||
FMT_ASSERT(false, "double support disabled");
|
FMT_ASSERT(false, "double support disabled");
|
||||||
#endif
|
|
||||||
break;
|
break;
|
||||||
case internal::type::long_double_type:
|
case internal::type::long_double_type:
|
||||||
#if FMT_USE_LONG_DOUBLE
|
if (internal::const_check(FMT_USE_LONG_DOUBLE))
|
||||||
internal::parse_float_type_spec(specs_, eh);
|
internal::parse_float_type_spec(specs_, eh);
|
||||||
#else
|
else
|
||||||
FMT_ASSERT(false, "long double support disabled");
|
FMT_ASSERT(false, "long double support disabled");
|
||||||
#endif
|
|
||||||
break;
|
break;
|
||||||
case internal::type::cstring_type:
|
case internal::type::cstring_type:
|
||||||
internal::handle_cstring_type_spec(
|
internal::handle_cstring_type_spec(
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user