🐛 use binary_t::value_type

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
Niels Lohmann 2025-06-01 16:18:00 +02:00
parent 64ebc6d511
commit 9e6240ad02
No known key found for this signature in database
GPG Key ID: 7F3CEA63AE251B69
3 changed files with 26 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,14 @@ 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<char> data;
const auto decoded = json_4804::from_cbor(data);
}
#endif
}
DOCTEST_CLANG_SUPPRESS_WARNING_POP