Commit 7476f5ee authored by christian's avatar christian

Make json_pointer::back const (resolves #1764)

parent 99d7518d
...@@ -267,7 +267,7 @@ class json_pointer ...@@ -267,7 +267,7 @@ class json_pointer
@since version 3.6.0 @since version 3.6.0
*/ */
const std::string& back() const std::string& back() const
{ {
if (JSON_HEDLEY_UNLIKELY(empty())) if (JSON_HEDLEY_UNLIKELY(empty()))
{ {
......
...@@ -10232,7 +10232,7 @@ class json_pointer ...@@ -10232,7 +10232,7 @@ class json_pointer
@since version 3.6.0 @since version 3.6.0
*/ */
const std::string& back() const std::string& back() const
{ {
if (JSON_HEDLEY_UNLIKELY(empty())) if (JSON_HEDLEY_UNLIKELY(empty()))
{ {
......
...@@ -559,6 +559,10 @@ TEST_CASE("JSON pointers") ...@@ -559,6 +559,10 @@ TEST_CASE("JSON pointers")
CHECK(!ptr.empty()); CHECK(!ptr.empty());
CHECK(j[ptr] == j["answer"]["everything"]); CHECK(j[ptr] == j["answer"]["everything"]);
// check access via const pointer
const auto cptr = ptr;
CHECK(cptr.back() == "everything");
ptr.pop_back(); ptr.pop_back();
ptr.pop_back(); ptr.pop_back();
CHECK(ptr.empty()); CHECK(ptr.empty());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment