From 29bb5c48b8ec9820c9514b4c6803cc00519bc759 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Mon, 28 Sep 2026 22:48:02 +0200 Subject: [PATCH] Give code outside basic_json the reference tokens of a json_pointer detail::json_pointer_access returns the reference tokens of a pointer, so that code resolving pointers without a basic_json value (such as the zero-copy view) does not have to parse to_string() again. No change in behavior. Signed-off-by: Niels Lohmann --- include/nlohmann/detail/json_pointer.hpp | 21 +++++++++++++++++++++ single_include/nlohmann/json.hpp | 21 +++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/include/nlohmann/detail/json_pointer.hpp b/include/nlohmann/detail/json_pointer.hpp index 78074988e..a23c0c91e 100644 --- a/include/nlohmann/detail/json_pointer.hpp +++ b/include/nlohmann/detail/json_pointer.hpp @@ -31,6 +31,11 @@ NLOHMANN_JSON_NAMESPACE_BEGIN +namespace detail +{ +struct json_pointer_access; +} // namespace detail + /// @brief JSON Pointer defines a string syntax for identifying a specific value within a JSON document /// @sa https://json.nlohmann.me/api/json_pointer/ template @@ -43,6 +48,8 @@ class json_pointer template friend class json_pointer; + friend struct detail::json_pointer_access; + template struct string_t_helper { @@ -1171,4 +1178,18 @@ inline bool operator<(const json_pointer& lhs, } #endif +namespace detail +{ +/// the reference tokens of a json_pointer, for code that resolves pointers +/// without a basic_json value (such as the zero-copy view) +struct json_pointer_access +{ + template + static const std::vector::string_t>& reference_tokens(const json_pointer& ptr) noexcept + { + return ptr.reference_tokens; + } +}; +} // namespace detail + NLOHMANN_JSON_NAMESPACE_END diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 9d63f822b..e0897a2d9 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -20153,6 +20153,11 @@ NLOHMANN_JSON_NAMESPACE_END NLOHMANN_JSON_NAMESPACE_BEGIN +namespace detail +{ +struct json_pointer_access; +} // namespace detail + /// @brief JSON Pointer defines a string syntax for identifying a specific value within a JSON document /// @sa https://json.nlohmann.me/api/json_pointer/ template @@ -20165,6 +20170,8 @@ class json_pointer template friend class json_pointer; + friend struct detail::json_pointer_access; + template struct string_t_helper { @@ -21293,6 +21300,20 @@ inline bool operator<(const json_pointer& lhs, } #endif +namespace detail +{ +/// the reference tokens of a json_pointer, for code that resolves pointers +/// without a basic_json value (such as the zero-copy view) +struct json_pointer_access +{ + template + static const std::vector::string_t>& reference_tokens(const json_pointer& ptr) noexcept + { + return ptr.reference_tokens; + } +}; +} // namespace detail + NLOHMANN_JSON_NAMESPACE_END // #include