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
+19 -2
View File
@@ -564,6 +564,14 @@ TEST_CASE("JSON pointers")
CHECK(!ptr.empty());
CHECK(j[ptr] == j["answer"]["everything"]);
ptr.pop_front();
CHECK(ptr.front() == "everything");
ptr.pop_front();
CHECK(ptr.empty());
ptr.push_front("everything");
ptr.push_front(answer);
CHECK(j[ptr] == j["answer"]["everything"]);
// check access via const pointer
const auto cptr = ptr;
CHECK(cptr.back() == "everything");
@@ -588,8 +596,17 @@ TEST_CASE("JSON pointers")
CHECK(ptr.empty());
CHECK(j[ptr] == j);
CHECK_THROWS_WITH(ptr.pop_back(),
"[json.exception.out_of_range.405] JSON pointer has no parent");
CHECK_THROWS_WITH_AS(ptr.pop_back(),
"[json.exception.out_of_range.405] JSON pointer has no parent", json::out_of_range&);
CHECK_THROWS_WITH_AS(ptr.back(),
"[json.exception.out_of_range.405] JSON pointer has no parent", json::out_of_range&);
CHECK_THROWS_WITH_AS(ptr.pop_front(),
"[json.exception.out_of_range.405] JSON pointer has no parent", json::out_of_range&);
CHECK_THROWS_WITH_AS(ptr.front(),
"[json.exception.out_of_range.405] JSON pointer has no parent", json::out_of_range&);
}
SECTION("operators")