From 2994bcd9e242eb065ee43e074a26714996084b83 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Fri, 25 Sep 2026 17:55:03 +0200 Subject: [PATCH] Select the BON8 float prefix by type get_bon8_float_prefix only depends on the type of its argument, so make the type a template parameter instead of passing an unused value. Signed-off-by: Niels Lohmann --- include/nlohmann/detail/output/binary_writer.hpp | 15 ++++++--------- single_include/nlohmann/json.hpp | 15 ++++++--------- 2 files changed, 12 insertions(+), 18 deletions(-) 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); }