mirror of
https://github.com/nlohmann/json.git
synced 2026-07-12 05:25:09 +00:00
Merge iterator+sentinel overloads and fix ambiguity/CI issues
Address PR review feedback and CI failures: - Merge the separate same-type and sentinel-type iterator overloads of parse(), accept(), sax_parse(), and the five from_* binary deserializers into a single overload with SentinelType defaulted to IteratorType, as suggested in review. Applied the same simplification to the detail::input_adapter() free functions. - Fix a latent ambiguity: some compilers (e.g. GCC 4.8) unreliably SFINAE the operator!= detection for std::nullptr_t against container/string types, making calls like parse(s, nullptr, ...) ambiguous with the compatible-input overload. can_compare_ne now explicitly excludes std::nullptr_t as a SentinelType. - Use a named enable_if_t template parameter instead of an unnamed function parameter for the SFINAE guard, fixing a clang-tidy hicpp-named-parameter/readability-named-parameter failure. - Update parse.md, accept.md, sax_parse.md, and the five from_*.md pages to document the merged overload instead of separate (2)/(3) overloads, also fixing an over-160-char line that broke the documentation style_check CI job. - Rework the BSON iterator+sentinel test to parse a BSON file already present in the test suite instead of writing/deleting a temp file. Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
+5
-11
@@ -1210,21 +1210,15 @@ TEST_CASE("BSON numerical data")
|
||||
|
||||
TEST_CASE("Parse BSON directly from a file using iterator and sentinel")
|
||||
{
|
||||
const json j = {{"key", "value"}, {"number", 42}};
|
||||
std::vector<std::uint8_t> bson_bytes;
|
||||
json::to_bson(j, bson_bytes);
|
||||
std::string const filename = TEST_DATA_DIRECTORY "/json.org/1.json";
|
||||
|
||||
{
|
||||
std::ofstream file("test_bson_sentinel.bson", std::ios::binary);
|
||||
file.write(reinterpret_cast<const char*>(bson_bytes.data()), static_cast<std::streamsize>(bson_bytes.size()));
|
||||
}
|
||||
std::ifstream f_json(filename);
|
||||
const json expected = json::parse(f_json);
|
||||
|
||||
std::ifstream file("test_bson_sentinel.bson", std::ios::binary);
|
||||
std::ifstream file(filename + ".bson", std::ios::binary);
|
||||
std::istreambuf_iterator<char> first(file);
|
||||
const json parsed = json::from_bson(first, utils::istreambuf_sentinel{});
|
||||
CHECK(parsed == j);
|
||||
|
||||
static_cast<void>(std::remove("test_bson_sentinel.bson"));
|
||||
CHECK(parsed == expected);
|
||||
}
|
||||
|
||||
TEST_CASE("BSON roundtrips" * doctest::skip())
|
||||
|
||||
Reference in New Issue
Block a user