Repository navigation
Add with_*_t alias templates to create basic_json types with changed template parameters - #5758
Conversation
126637c to
ea72ffe
Compare
| - 'update': api/basic_json/update.md | ||
| - 'value': api/basic_json/value.md | ||
| - 'value_t': api/basic_json/value_t.md | ||
| - 'with_t': api/basic_json/with_t.md |
There was a problem hiding this comment.
Seems weird that this isn't indented. Intentional?
There was a problem hiding this comment.
Not intentional, thanks — the entry ended up at the top level of nav. Fixed in 8ab8fa9.
(Written by Claude Code.)
|
Because this is a nested template type, these can chain. This is not obvious and should probably be called out with an example. Also, that it can start with I did verify that |
|
Good point, thanks for checking. 8ab8fa9 adds a paragraph to using my_json = nlohmann::json::with_integers_t<int, unsigned int>::with_float_t<float>;It also notes that the order of chained aliases does not matter and that (Written by Claude Code.) |
…odified template parameters 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>
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>
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>
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>
8ab8fa9 to
a4c4400
Compare
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
|
@nlohmann Would you want to update the tests and examples to use this new functionality? If so, would you prefer In looking at this, I found a few places where only |
|
Thanks! Yes, done in #5787. It uses (Written by Claude Code on behalf of @nlohmann.) |
Sounds good. |
Adds member alias templates to
basic_jsonthat create abasic_jsontype with one of its template parameters replaced, so you don't have to spell out all eleven:Aliases:
with_object_t,with_array_t,with_string_t,with_boolean_t,with_integers_t<I, U>,with_float_t,with_allocator_t,with_json_serializer_t,with_binary_t,with_base_class_t. Together they cover all template parameters. They are members, so they also work fromordered_jsonor any other specialization and keep its other parameters.This takes over #3898 by @barcode, which went stale. Their commit is included with them as author. On top of it, following the review in #3898:
with_changed_*_tis renamed to the shorterwith_*_t.with_integers_t<I, U>(@gregmarr's suggestion), because the two are usually changed together.api/basic_json/with_t.mdwith an example, linked from thebasic_jsonindex andmkdocs.yml.std::is_sametests for every alias inunit-udt.cpp, including one that checksordered_json::with_string_tkeepsordered_map.Supersedes #3898. Thanks @barcode!
Public API
Only additions: ten new public member alias templates on
basic_json. Nothing existing changes. No breaking changes.🤖 Generated with Claude Code