From 97f724951b061b58905830ecd4da4ceac85c57a0 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Sun, 4 Oct 2026 18:01:49 +0200 Subject: [PATCH] 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 - 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 --- .../docs/examples/json_base_class_t.cpp | 2 +- include/nlohmann/json.hpp | 41 +++++++------ single_include/nlohmann/json.hpp | 59 ++++++++++--------- tests/src/unit-allocator.cpp | 6 +- tests/src/unit-alt-string.cpp | 2 +- tests/src/unit-custom-base-class.cpp | 4 +- tests/src/unit-udt.cpp | 4 +- 7 files changed, 64 insertions(+), 54 deletions(-) diff --git a/docs/mkdocs/docs/examples/json_base_class_t.cpp b/docs/mkdocs/docs/examples/json_base_class_t.cpp index e157ba26c..1dafd417f 100644 --- a/docs/mkdocs/docs/examples/json_base_class_t.cpp +++ b/docs/mkdocs/docs/examples/json_base_class_t.cpp @@ -13,7 +13,7 @@ class visitor_adaptor_with_metadata void do_visit(const Ptr& ptr, const Fnc& fnc) const; }; -using json = nlohmann::json::with_changed_base_class_t; +using json = nlohmann::json::with_base_class_t; template void visitor_adaptor_with_metadata::visit(const Fnc& fnc) const diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index 81a860797..601d014cd 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -231,58 +231,63 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec //////////////////////////////////////////////////////////////////////////////// /// Json type using a different type for storing objects + /// @sa https://json.nlohmann.me/api/basic_json/with_t/ template class ObjectType2> - using with_changed_object_t = basic_json; /// Json type using a different type for storing arrays + /// @sa https://json.nlohmann.me/api/basic_json/with_t/ template class ArrayType2> - using with_changed_array_t = basic_json; /// Json type using a different type for storing strings + /// @sa https://json.nlohmann.me/api/basic_json/with_t/ template - using with_changed_string_t = basic_json; /// Json type using a different type for storing booleans + /// @sa https://json.nlohmann.me/api/basic_json/with_t/ template - using with_changed_boolean_t = basic_json; - /// Json type using a different type for storing signed integers - template - using with_changed_integer_t = basic_json; - - /// Json type using a different type for storing unsigned integers - template - using with_changed_unsigned_t = basic_json; + /// Json type using different types for storing signed and unsigned integers + /// @sa https://json.nlohmann.me/api/basic_json/with_t/ + template + using with_integers_t = basic_json; /// Json type using a different type for storing floating point numbers + /// @sa https://json.nlohmann.me/api/basic_json/with_t/ template - using with_changed_float_t = basic_json; /// Json type using a different type as base allocator + /// @sa https://json.nlohmann.me/api/basic_json/with_t/ template class AllocatorType2> - using with_changed_allocator_t = basic_json; /// Json type using a different type as json serializer + /// @sa https://json.nlohmann.me/api/basic_json/with_t/ template class JSONSerializer2> - using with_changed_json_serializer_t = basic_json; /// Json type using a different type for storing binary data + /// @sa https://json.nlohmann.me/api/basic_json/with_t/ template - using with_changed_binary_t = basic_json; /// Json type using a different type as base class + /// @sa https://json.nlohmann.me/api/basic_json/with_t/ template - using with_changed_base_class_t = basic_json; //////////////// diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 8fe9eafce..4dfe1cf29 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -27353,59 +27353,64 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec //////////////////////////////////////////////////////////////////////////////// /// Json type using a different type for storing objects + /// @sa https://json.nlohmann.me/api/basic_json/with_t/ template class ObjectType2> - using with_changed_object_t = basic_json; + using with_object_t = basic_json; /// Json type using a different type for storing arrays + /// @sa https://json.nlohmann.me/api/basic_json/with_t/ template class ArrayType2> - using with_changed_array_t = basic_json; + using with_array_t = basic_json; /// Json type using a different type for storing strings + /// @sa https://json.nlohmann.me/api/basic_json/with_t/ template - using with_changed_string_t = basic_json; + using with_string_t = basic_json; /// Json type using a different type for storing booleans + /// @sa https://json.nlohmann.me/api/basic_json/with_t/ template - using with_changed_boolean_t = basic_json; + using with_boolean_t = basic_json; - /// Json type using a different type for storing signed integers - template - using with_changed_integer_t = basic_json; - - /// Json type using a different type for storing unsigned integers - template - using with_changed_unsigned_t = basic_json; + /// Json type using different types for storing signed and unsigned integers + /// @sa https://json.nlohmann.me/api/basic_json/with_t/ + template + using with_integers_t = basic_json; /// Json type using a different type for storing floating point numbers + /// @sa https://json.nlohmann.me/api/basic_json/with_t/ template - using with_changed_float_t = basic_json; + using with_float_t = basic_json; /// Json type using a different type as base allocator + /// @sa https://json.nlohmann.me/api/basic_json/with_t/ template class AllocatorType2> - using with_changed_allocator_t = basic_json; + using with_allocator_t = basic_json; /// Json type using a different type as json serializer + /// @sa https://json.nlohmann.me/api/basic_json/with_t/ template class JSONSerializer2> - using with_changed_json_serializer_t = basic_json; + using with_json_serializer_t = basic_json; /// Json type using a different type for storing binary data + /// @sa https://json.nlohmann.me/api/basic_json/with_t/ template - using with_changed_binary_t = basic_json; + using with_binary_t = basic_json; /// Json type using a different type as base class + /// @sa https://json.nlohmann.me/api/basic_json/with_t/ template - using with_changed_base_class_t = basic_json; + using with_base_class_t = basic_json; //////////////// // exceptions // diff --git a/tests/src/unit-allocator.cpp b/tests/src/unit-allocator.cpp index 1d1579713..6e908ccaa 100644 --- a/tests/src/unit-allocator.cpp +++ b/tests/src/unit-allocator.cpp @@ -48,7 +48,7 @@ TEST_CASE("bad_alloc") SECTION("bad_alloc") { // create JSON type using the throwing allocator - using bad_json = nlohmann::json::with_changed_allocator_t; + using bad_json = nlohmann::json::with_allocator_t; // creating an object should throw CHECK_THROWS_AS(bad_json(bad_json::value_t::object), std::bad_alloc&); @@ -122,7 +122,7 @@ void my_allocator_clean_up(T* p) TEST_CASE("controlled bad_alloc") { // create JSON type using the throwing allocator - using my_json = nlohmann::json::with_changed_allocator_t; + using my_json = nlohmann::json::with_allocator_t; SECTION("class json_value") { @@ -574,7 +574,7 @@ TEST_CASE("bad my_allocator::construct") { SECTION("my_allocator::construct doesn't forward") { - using bad_alloc_json = nlohmann::json::with_changed_allocator_t; + using bad_alloc_json = nlohmann::json::with_allocator_t; bad_alloc_json j; j["test"] = bad_alloc_json::array_t(); diff --git a/tests/src/unit-alt-string.cpp b/tests/src/unit-alt-string.cpp index 1168304eb..961cd742b 100644 --- a/tests/src/unit-alt-string.cpp +++ b/tests/src/unit-alt-string.cpp @@ -163,7 +163,7 @@ void int_to_string(alt_string& target, std::size_t value) target = std::to_string(value).c_str(); } -using alt_json = nlohmann::json::with_changed_string_t; +using alt_json = nlohmann::json::with_string_t; bool operator<(const char* op1, const alt_string& op2) noexcept { diff --git a/tests/src/unit-custom-base-class.cpp b/tests/src/unit-custom-base-class.cpp index 8043919ef..9718d1cda 100644 --- a/tests/src/unit-custom-base-class.cpp +++ b/tests/src/unit-custom-base-class.cpp @@ -38,7 +38,7 @@ class json_metadata }; template -using json_with_metadata = nlohmann::json::with_changed_base_class_t>; +using json_with_metadata = nlohmann::json::with_base_class_t>; TEST_CASE("JSON Node Metadata") { @@ -255,7 +255,7 @@ class visitor_adaptor void do_visit(const Ptr& ptr, const Fnc& fnc) const; }; -using json_with_visitor_t = nlohmann::json::with_changed_base_class_t; +using json_with_visitor_t = nlohmann::json::with_base_class_t; template void visitor_adaptor::visit(const Fnc& fnc) const diff --git a/tests/src/unit-udt.cpp b/tests/src/unit-udt.cpp index 21926b04d..11d4940f4 100644 --- a/tests/src/unit-udt.cpp +++ b/tests/src/unit-udt.cpp @@ -684,7 +684,7 @@ static std::ostream& operator<<(std::ostream& os, small_pod l) TEST_CASE("custom serializer for pods" * doctest::test_suite("udt")) { using custom_json = - nlohmann::json::with_changed_json_serializer_t; + nlohmann::json::with_json_serializer_t; auto p = udt::small_pod{42, '/', 42}; custom_json const j = p; @@ -702,7 +702,7 @@ TEST_CASE("custom serializer for pods" * doctest::test_suite("udt")) template struct another_adl_serializer; -using custom_json = nlohmann::json::with_changed_json_serializer_t; +using custom_json = nlohmann::json::with_json_serializer_t; template struct another_adl_serializer