diff --git a/include/nlohmann/detail/output/binary_writer.hpp b/include/nlohmann/detail/output/binary_writer.hpp index db6c90394..9f6d0167f 100644 --- a/include/nlohmann/detail/output/binary_writer.hpp +++ b/include/nlohmann/detail/output/binary_writer.hpp @@ -1447,14 +1447,11 @@ class binary_writer return to_char_type(0xCB); // float 64 } - static constexpr CharType get_bon8_float_prefix(float /*unused*/) + /// @return the BON8 type marker for binary32 (float) or binary64 (double) + template + static constexpr CharType get_bon8_float_prefix() { - return to_char_type(0x8E); // binary32 - } - - static constexpr CharType get_bon8_float_prefix(double /*unused*/) - { - return to_char_type(0x8F); // binary64 + return to_char_type(std::is_same::value ? 0x8E : 0x8F); } //////////// @@ -2511,7 +2508,7 @@ class binary_writer oa.write_character(format == detail::input_format_t::cbor ? get_cbor_float_prefix(static_cast(n)) : format == detail::input_format_t::bon8 - ? get_bon8_float_prefix(static_cast(n)) + ? get_bon8_float_prefix() : get_msgpack_float_prefix(static_cast(n))); write_number(static_cast(n)); } @@ -2520,7 +2517,7 @@ class binary_writer oa.write_character(format == detail::input_format_t::cbor ? get_cbor_float_prefix(n) : format == detail::input_format_t::bon8 - ? get_bon8_float_prefix(n) + ? get_bon8_float_prefix() : get_msgpack_float_prefix(n)); write_number(n); } diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index dadda405c..dd5804f4e 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -21000,14 +21000,11 @@ class binary_writer return to_char_type(0xCB); // float 64 } - static constexpr CharType get_bon8_float_prefix(float /*unused*/) + /// @return the BON8 type marker for binary32 (float) or binary64 (double) + template + static constexpr CharType get_bon8_float_prefix() { - return to_char_type(0x8E); // binary32 - } - - static constexpr CharType get_bon8_float_prefix(double /*unused*/) - { - return to_char_type(0x8F); // binary64 + return to_char_type(std::is_same::value ? 0x8E : 0x8F); } //////////// @@ -22064,7 +22061,7 @@ class binary_writer oa.write_character(format == detail::input_format_t::cbor ? get_cbor_float_prefix(static_cast(n)) : format == detail::input_format_t::bon8 - ? get_bon8_float_prefix(static_cast(n)) + ? get_bon8_float_prefix() : get_msgpack_float_prefix(static_cast(n))); write_number(static_cast(n)); } @@ -22073,7 +22070,7 @@ class binary_writer oa.write_character(format == detail::input_format_t::cbor ? get_cbor_float_prefix(n) : format == detail::input_format_t::bon8 - ? get_bon8_float_prefix(n) + ? get_bon8_float_prefix() : get_msgpack_float_prefix(n)); write_number(n); }