Repository navigation
Add helper types to make it easier to create a basic_json type with modified template parameters - #3898
Add helper types to make it easier to create a basic_json type with modified template parameters#3898barcode wants to merge 1 commit into
Conversation
dc4517a to
445e5ff
Compare
445e5ff to
134929c
Compare
|
Work on this PR is done and it only needs a review. |
…odified template parameters
134929c to
0d9f46f
Compare
|
This pull request has been marked as stale because it has had no activity for 30 days. While we won’t close it automatically, we encourage you to update or comment if it is still relevant. Keeping pull requests active and up-to-date helps us review and merge changes more efficiently. Thank you for your contributions! |
|
Sorry for letting this sit for so long, @barcode — this fell through the cracks, and it's not for lack of merit. To answer your open questions:
If you're still interested, could you:
If you no longer have time for this, just let us know and we'll take it from here. (This comment was written by Claude Code on behalf of @nlohmann.) |
gregmarr
left a comment
There was a problem hiding this comment.
I also wonder if there are any other common cases that replace two or three elements. I don't think we'd want to have ALL of those, but maybe add them as we find them actually useful.
|
|
||
| /// Json type using a different type for storing unsigned integers | ||
| template<class NumberUnsignedType2> | ||
| using with_changed_unsigned_t = basic_json<ObjectType, ArrayType, StringType, BooleanType, |
There was a problem hiding this comment.
I wonder how often someone changes integer but not unsigned or vice-versa. Should these two be combined into a single version that takes both?
There was a problem hiding this comment.
What about with_integers_t<I, U>?
There was a problem hiding this comment.
Yes, I was thinking something like that.
|
Thanks a lot for this, @barcode! Since we didn't hear back, we continued in #5758. Your commit is included there with you as author. On top of it, the aliases were renamed to This comment was written by Claude Code on behalf of @nlohmann. |
…d aliases Per review discussion on #3898 between gregmarr and nlohmann: - rename with_changed_X_t to with_X_t for brevity - replace the separate with_changed_integer_t/with_changed_unsigned_t aliases with a single with_integers_t<NumberIntegerType2, NumberUnsignedType2> - add @sa doc comment links for the upcoming documentation page Co-authored-by: Raphael Grimm <1005058+barcode@users.noreply.github.com> Signed-off-by: Niels Lohmann <mail@nlohmann.me>
…d aliases Per review discussion on #3898 between gregmarr and nlohmann: - rename with_changed_X_t to with_X_t for brevity - replace the separate with_changed_integer_t/with_changed_unsigned_t aliases with a single with_integers_t<NumberIntegerType2, NumberUnsignedType2> - add @sa doc comment links for the upcoming documentation page Co-authored-by: Raphael Grimm <1005058+barcode@users.noreply.github.com> Signed-off-by: Niels Lohmann <mail@nlohmann.me>
…template parameters (#5758) * Add helper types to make it easier to create a basic_json type with modified template parameters Signed-off-by: Niels Lohmann <mail@nlohmann.me> * Rename with_changed_*_t aliases to with_*_t and merge integer/unsigned aliases Per review discussion on #3898 between gregmarr and nlohmann: - rename with_changed_X_t to with_X_t for brevity - replace the separate with_changed_integer_t/with_changed_unsigned_t aliases with a single with_integers_t<NumberIntegerType2, NumberUnsignedType2> - add @sa doc comment links for the upcoming documentation page Co-authored-by: Raphael Grimm <1005058+barcode@users.noreply.github.com> Signed-off-by: Niels Lohmann <mail@nlohmann.me> * Add documentation for the with_*_t member alias templates Add docs/mkdocs/docs/api/basic_json/with_t.md documenting with_object_t, with_array_t, with_string_t, with_boolean_t, with_integers_t, with_float_t, with_allocator_t, with_json_serializer_t, with_binary_t and with_base_class_t, with an accompanying example, and link the page from the basic_json member types list and the mkdocs navigation. Co-authored-by: Raphael Grimm <1005058+barcode@users.noreply.github.com> Signed-off-by: Niels Lohmann <mail@nlohmann.me> * Add tests for the with_*_t member alias templates Check with std::is_same that each with_*_t alias produces the expected basic_json type, and that with_string_t keeps nlohmann::ordered_map as the object type when used on ordered_json. Co-authored-by: Raphael Grimm <1005058+barcode@users.noreply.github.com> Signed-off-by: Niels Lohmann <mail@nlohmann.me> * Fix with_t nav entry and document chaining of the with_*_t aliases Indent the with_t entry in mkdocs.yml so it is listed under basic_json, explain that the aliases can be chained and work on ordered_json, and test both, including json::with_object_t<ordered_map> == ordered_json. Signed-off-by: Niels Lohmann <mail@nlohmann.me> * Add docset entry for basic_json::with_t Signed-off-by: Niels Lohmann <mail@nlohmann.me> --------- Signed-off-by: Niels Lohmann <mail@nlohmann.me> Co-authored-by: barcode <barcode@example.com> Co-authored-by: Raphael Grimm <1005058+barcode@users.noreply.github.com>
(First part of the points listed in #3110 (comment), the rest is done in a different PR to prevent mixing of separate issues / features)
This PR adds member templates to
nlohmann::jsonwhich can be used to create abasic_jsontype with one replaced template parameter (e.g.nlohmann::json::with_changed_json_serializer_t<T>).Tests and examples were modified to use those templates (except for regression tests).
Open questions from my side:
with_changed_*) or rather use something else (e.g.with_*)?In case this will be added, i will write the documentation.
Pull request checklist
Read the Contribution Guidelines for detailed information.
include/nlohmanndirectory, runmake amalgamateto create the single-header filessingle_include/nlohmann/json.hppandsingle_include/nlohmann/json_fwd.hpp. The whole process is described here.