nlohmann / json

JSON for Modern C++
https://json.nlohmann.me
MIT License
41.25k stars 6.57k forks source link

Make iterator_proxy_value a forward_iterator (#4371) #4372

Open captaincrutches opened 1 month ago

captaincrutches commented 1 month ago

See #4371 for all the details - but long story short, there seems to be no reason not to expose iterator_proxy_value as a forward_iterator instead of just an input_iterator. This allows more use cases when items() is fed into C++20 std::views.

If there is a reason not to do so, please let me know - but the iterator_category on this type currently seems to long predate the more recent change to fix it for C++20 ranges initially. As well, the actual json iterator which the proxy wraps is also a forward iterator, so this keeps them on par with each other in terms of capabilities.

Another option is to remove this iterator_category typedef entirely, and let iterator_traits deduce it - since the type otherwise satisfies ForwardIterator, it should (and does, in my motivating case) do the right thing. But since the other required typedefs are here, might as well keep it but change it IMO.

I'm not sure what, if any, tests can/should be updated/added in this case - I'm open to suggestions, though it seems like all the relevant static_asserts and such should still apply.


Pull request checklist

Read the Contribution Guidelines for detailed information.

Note on amalgamation: I did run make amalgamate, and that touched a bunch of lines unrelated to my change. The actual change I've made is to iterator_proxy.hpp, and hopefully hiding whitespace in the diff will narrow that down. If you'd rather I revert the other amalgamate changes to keep this diff confined to the 2 (well, 4, including generated code) lines I changed, I'm more than happy to do so - but I figured I'd err on the side of caution w.r.t. any checks that run in CI.

captaincrutches commented 1 month ago

Ahh - I see from the build logs that these jobs use astyle 3.1; when I ran make amalgamate, I installed astyle 3.4.

Re-running with the matching version of astyle produces much saner results :) Though it still does remove a bunch of blank lines in the single-include headers.

github-actions[bot] commented 1 month ago

🔴 Amalgamation check failed! 🔴

The source code has not been amalgamated. @captaincrutches Please read and follow the Contribution Guidelines.

coveralls commented 1 month ago

Coverage Status

coverage: 100.0%. remained the same when pulling 104cdd896d0fbded51ce6a46fad4223bbb396a78 on captaincrutches:cc-iterator into 8c391e04fe4195d8be862c97f38cfe10e2a3472e on nlohmann:develop.

captaincrutches commented 1 month ago

Okay, I reset the single-include files entirely and tried again, and now we've got a diff that actually looks correct. Sorry for the noise! I'm happy to rebase and clean up these extra bad commits if that would be preferable.

captaincrutches commented 1 month ago

Clang-tidy failures look unrelated to my change - looks like https://github.com/nlohmann/json/pull/4311 already exists trying to fix them.

I'm not sure what to make of the xcode 12.4 build - seems like something stalled out and hit a timeout, but I can't tell what... the rest of the build looks like it was going fine up until it stopped in its tracks.

nlohmann commented 1 month ago

I'll check the Clang-Tidy warnings.