Use binary_t::value_type (#4805)

This commit is contained in:
Niels Lohmann 2025-06-02 06:35:27 +02:00 committed by GitHub
parent b19f058465
commit cf16c5ab9f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 27 additions and 2 deletions

View File

@ -2944,7 +2944,7 @@ class binary_reader
success = false;
break;
}
result.push_back(static_cast<std::uint8_t>(current));
result.push_back(static_cast<typename binary_t::value_type>(current));
}
return success;
}

View File

@ -12765,7 +12765,7 @@ class binary_reader
success = false;
break;
}
result.push_back(static_cast<std::uint8_t>(current));
result.push_back(static_cast<typename binary_t::value_type>(current));
}
return success;
}

View File

@ -42,6 +42,22 @@ using ordered_json = nlohmann::ordered_json;
#elif __has_include(<experimental/optional>)
#include <experimental/optional>
#endif
/////////////////////////////////////////////////////////////////////
// for #4804
/////////////////////////////////////////////////////////////////////
using json_4804 = nlohmann::basic_json<std::map, // ObjectType
std::vector, // ArrayType
std::string, // StringType
bool, // BooleanType
std::int64_t, // NumberIntegerType
std::uint64_t, // NumberUnsignedType
double, // NumberFloatType
std::allocator, // AllocatorType
nlohmann::adl_serializer, // JSONSerializer
std::vector<std::byte>, // BinaryType
void // CustomBaseClass
>;
#endif
#ifdef JSON_HAS_CPP_20
@ -1094,6 +1110,15 @@ TEST_CASE("regression tests 2")
CHECK(j.type_name() == "invalid");
}
#endif
#ifdef JSON_HAS_CPP_17
SECTION("issue #4804: from_cbor incompatible with std::vector<std::byte> as binary_t")
{
const std::vector<std::uint8_t> data = {0x80};
const auto decoded = json_4804::from_cbor(data);
CHECK((decoded == json_4804::array()));
}
#endif
}
TEST_CASE_TEMPLATE("issue #4798 - nlohmann::json::to_msgpack() encode float NaN as double", T, double, float) // NOLINT(readability-math-missing-parentheses)