Add front methods to json_pointers (implements #4889) (#5152)

* Added front, pop_front, and push_front methods to json_pointers in order to facilitate root-to-leaf traversals of JSON object trees. (#4889)

Signed-off-by: trdesilva <5818730+trdesilva@users.noreply.github.com>

* undid VS autoformatting in irrelevant code

Signed-off-by: trdesilva <5818730+trdesilva@users.noreply.github.com>

* Ran make amalgamate, added navigation to json_pointer's new front methods in mkdocs, and fixed errors in documented complexity for those methods.

Signed-off-by: trdesilva <5818730+trdesilva@users.noreply.github.com>

* Fixed GCC 4.8 compile error caused by const iterators

Signed-off-by: trdesilva <5818730+trdesilva@users.noreply.github.com>

* Fixed another gcc-4.8 compile error

Signed-off-by: trdesilva <5818730+trdesilva@users.noreply.github.com>

* amalgamated

Signed-off-by: trdesilva <5818730+trdesilva@users.noreply.github.com>

---------

Signed-off-by: trdesilva <5818730+trdesilva@users.noreply.github.com>
This commit is contained in:
trdesilva
2026-05-12 22:59:16 -07:00
committed by GitHub
parent 216c50365e
commit a0a4e7cc0b
14 changed files with 274 additions and 2 deletions
+38
View File
@@ -14872,6 +14872,44 @@ class json_pointer
return res;
}
/// @brief remove first reference token
/// @sa https://json.nlohmann.me/api/json_pointer/pop_front/
void pop_front()
{
if (JSON_HEDLEY_UNLIKELY(empty()))
{
JSON_THROW(detail::out_of_range::create(405, "JSON pointer has no parent", nullptr));
}
reference_tokens.erase(reference_tokens.begin());
}
/// @brief return first reference token
/// @sa https://json.nlohmann.me/api/json_pointer/front/
const string_t& front() const
{
if (JSON_HEDLEY_UNLIKELY(empty()))
{
JSON_THROW(detail::out_of_range::create(405, "JSON pointer has no parent", nullptr));
}
return reference_tokens.front();
}
/// @brief append an unescaped token at the start of the reference pointer
/// @sa https://json.nlohmann.me/api/json_pointer/push_front/
void push_front(const string_t& token)
{
reference_tokens.insert(reference_tokens.begin(), token);
}
/// @brief append an unescaped token at the start of the reference pointer
/// @sa https://json.nlohmann.me/api/json_pointer/push_front/
void push_front(string_t&& token)
{
reference_tokens.insert(reference_tokens.begin(), std::move(token));
}
/// @brief remove last reference token
/// @sa https://json.nlohmann.me/api/json_pointer/pop_back/
void pop_back()