Make json_pointer::back const (resolves #1764)
Added const to json_pointer::back()
Extended unit-json_pointer.cpp to make use of back() on const object.

* * *

## Pull request checklist

Read the [Contribution Guidelines](https://github.com/nlohmann/json/blob/develop/.github/CONTRIBUTING.md) for detailed information.

- [x]  Changes are described in the pull request, or an [existing issue is referenced](https://github.com/nlohmann/json/issues).
- [x]  The test suite [compiles and runs](https://github.com/nlohmann/json/blob/develop/README.md#execute-unit-tests) without error.
- [x]  [Code coverage](https://coveralls.io/github/nlohmann/json) is 100%. Test cases can be added by editing the [test suite](https://github.com/nlohmann/json/tree/develop/test/src).
- [x]  The source code is amalgamated; that is, after making changes to the sources in the `include/nlohmann` directory, run `make amalgamate` to create the single-header file `single_include/nlohmann/json.hpp`. The whole process is described [here](https://github.com/nlohmann/json/blob/develop/.github/CONTRIBUTING.md#files-to-change).

{"label": "nlohmann:develop", "ref": "develop", "sha": "99d7518d21cbbfe91d341a5431438bf7559c6974"}
- What is the issue you have?
It is impossible su use `json_pointer<>::back()` on `const json_pointer`.

- What is the expected behavior?
I expect to be able to use on a const. Since it returns a `const std::string&`, and since it is implemented with `std::vector<>::back()` that has a `const` overload, I expect the `json_pointer<>::back()` has to be declared `const`.

- And what is the actual behavior instead?
The function is not marked as `const`.

- Did you use a released version of the library or the version from the `develop` branch?
tested with 3.7.0.

json_pointer<>::back() should be const
diff --git a/include/nlohmann/detail/json_pointer.hpp b/include/nlohmann/detail/json_pointer.hpp
index 9076441c89..041408a80f 100644
--- a/include/nlohmann/detail/json_pointer.hpp
+++ b/include/nlohmann/detail/json_pointer.hpp
@@ -267,7 +267,7 @@ class json_pointer
 
     @since version 3.6.0
     */
-    const std::string& back()
+    const std::string& back() const
     {
         if (JSON_HEDLEY_UNLIKELY(empty()))
         {
diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp
index d27940b85c..f7aedd1028 100644
--- a/single_include/nlohmann/json.hpp
+++ b/single_include/nlohmann/json.hpp
@@ -10232,7 +10232,7 @@ class json_pointer
 
     @since version 3.6.0
     */
-    const std::string& back()
+    const std::string& back() const
     {
         if (JSON_HEDLEY_UNLIKELY(empty()))
         {

diff --git a/test/src/unit-json_pointer.cpp b/test/src/unit-json_pointer.cpp
index 9746d80d33..2fa3033cd0 100644
--- a/test/src/unit-json_pointer.cpp
+++ b/test/src/unit-json_pointer.cpp
@@ -559,6 +559,10 @@ TEST_CASE("JSON pointers")
         CHECK(!ptr.empty());
         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();
         CHECK(ptr.empty());

{"test-json_pointer_default": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-regression_all": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-element_access2_default": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-bson_all": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-items_all": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-modifiers_all": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-constructor1_all": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-reference_access_default": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "cmake_import_build": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-comparison_default": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-class_lexer_default": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-class_const_iterator_all": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-wstring_default": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-class_iterator_all": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "cmake_import_minver_build": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-udt_all": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-class_const_iterator_default": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "cmake_add_subdirectory_configure": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-constructor2_default": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-cbor_all": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-allocator_default": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-inspection_all": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-algorithms_all": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-testsuites_default": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-comparison_all": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-to_chars_all": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-constructor2_all": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-meta_all": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-allocator_all": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-readme_all": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-concepts_all": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-unicode_default": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-pointer_access_default": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-serialization_all": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-msgpack_default": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-msgpack_all": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-regression_default": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-convenience_all": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-conversions_default": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-class_parser_default": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-element_access1_all": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-wstring_all": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-readme_default": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-noexcept_default": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-element_access1_default": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-inspection_default": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-class_iterator_default": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-bson_default": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-algorithms_default": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-unicode_all": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-alt-string_all": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-alt-string_default": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-items_default": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "cmake_import_minver_configure": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-conversions_all": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-noexcept_all": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-concepts_default": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-merge_patch_default": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-iterators2_all": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-pointer_access_all": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-iterators1_all": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-constructor1_default": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-cbor_default": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-modifiers_default": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-json_patch_all": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-to_chars_default": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-capacity_all": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-element_access2_all": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-ubjson_all": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-serialization_default": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-testsuites_all": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-iterators1_default": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-udt_default": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-reference_access_all": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-class_lexer_all": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-capacity_default": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-json_patch_default": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-json_pointer_all": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-class_parser_all": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-merge_patch_all": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-iterators2_default": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "cmake_import_configure": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-deserialization_all": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-ubjson_default": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-convenience_default": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-meta_default": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "cmake_add_subdirectory_build": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-deserialization_default": {"run": "PASS", "test": "NONE", "fix": "PASS"}}
{"test-json_pointer_default": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-regression_all": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-element_access2_default": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-bson_all": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-items_all": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-modifiers_all": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-constructor1_all": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-reference_access_default": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "cmake_import_build": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-comparison_default": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-class_lexer_default": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-class_const_iterator_all": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-wstring_default": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-class_iterator_all": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "cmake_import_minver_build": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-udt_all": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-class_const_iterator_default": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "cmake_add_subdirectory_configure": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-constructor2_default": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-cbor_all": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-allocator_default": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-inspection_all": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-algorithms_all": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-testsuites_default": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-comparison_all": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-to_chars_all": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-constructor2_all": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-meta_all": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-allocator_all": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-readme_all": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-concepts_all": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-unicode_default": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-pointer_access_default": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-serialization_all": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-msgpack_default": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-msgpack_all": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-regression_default": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-convenience_all": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-conversions_default": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-class_parser_default": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-element_access1_all": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-wstring_all": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-readme_default": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-noexcept_default": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-element_access1_default": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-inspection_default": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-class_iterator_default": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-bson_default": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-algorithms_default": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-unicode_all": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-alt-string_all": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-alt-string_default": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-items_default": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "cmake_import_minver_configure": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-conversions_all": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-noexcept_all": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-concepts_default": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-merge_patch_default": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-iterators2_all": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-pointer_access_all": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-iterators1_all": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-constructor1_default": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-cbor_default": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-modifiers_default": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-json_patch_all": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-to_chars_default": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-capacity_all": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-element_access2_all": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-ubjson_all": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-serialization_default": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-testsuites_all": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-iterators1_default": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-udt_default": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-reference_access_all": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-class_lexer_all": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-capacity_default": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-json_patch_default": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-json_pointer_all": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-class_parser_all": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-merge_patch_all": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-iterators2_default": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "cmake_import_configure": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-deserialization_all": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-ubjson_default": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-convenience_default": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-meta_default": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "cmake_add_subdirectory_build": {"run": "PASS", "test": "NONE", "fix": "PASS"}, "test-deserialization_default": {"run": "PASS", "test": "NONE", "fix": "PASS"}}
{"passed_count": 88, "failed_count": 0, "skipped_count": 0, "passed_tests": ["test-regression_all", "test-element_access2_default", "test-items_all", "test-reference_access_default", "test-comparison_default", "test-class_const_iterator_all", "test-wstring_default", "cmake_import_minver_build", "test-udt_all", "test-class_const_iterator_default", "cmake_add_subdirectory_configure", "test-constructor2_default", "test-cbor_all", "test-allocator_default", "test-testsuites_default", "test-to_chars_all", "test-allocator_all", "test-readme_all", "test-pointer_access_default", "test-msgpack_all", "test-regression_default", "test-conversions_default", "test-wstring_all", "test-readme_default", "test-noexcept_default", "test-class_iterator_default", "test-algorithms_default", "test-alt-string_all", "test-alt-string_default", "test-items_default", "cmake_import_minver_configure", "test-merge_patch_default", "test-constructor1_default", "test-cbor_default", "test-iterators1_default", "test-udt_default", "test-reference_access_all", "test-capacity_default", "test-meta_default", "cmake_add_subdirectory_build", "test-json_pointer_default", "test-bson_all", "test-modifiers_all", "test-constructor1_all", "cmake_import_build", "test-class_lexer_default", "test-class_iterator_all", "test-inspection_all", "test-algorithms_all", "test-comparison_all", "test-constructor2_all", "test-meta_all", "test-concepts_all", "test-unicode_default", "test-serialization_all", "test-msgpack_default", "test-convenience_all", "test-class_parser_default", "test-element_access1_all", "test-element_access1_default", "test-inspection_default", "test-bson_default", "test-unicode_all", "test-conversions_all", "test-noexcept_all", "test-concepts_default", "test-iterators2_all", "test-pointer_access_all", "test-iterators1_all", "test-modifiers_default", "test-json_patch_all", "test-to_chars_default", "test-capacity_all", "test-element_access2_all", "test-ubjson_all", "test-serialization_default", "test-testsuites_all", "test-class_lexer_all", "test-json_patch_default", "test-json_pointer_all", "test-class_parser_all", "test-merge_patch_all", "test-iterators2_default", "cmake_import_configure", "test-deserialization_all", "test-ubjson_default", "test-convenience_default", "test-deserialization_default"], "failed_tests": [], "skipped_tests": []}
{"passed_count": 0, "failed_count": 0, "skipped_count": 0, "passed_tests": [], "failed_tests": [], "skipped_tests": []}
{"passed_count": 88, "failed_count": 0, "skipped_count": 0, "passed_tests": ["test-regression_all", "test-element_access2_default", "test-items_all", "test-reference_access_default", "test-comparison_default", "test-class_const_iterator_all", "test-wstring_default", "cmake_import_minver_build", "test-udt_all", "test-class_const_iterator_default", "cmake_add_subdirectory_configure", "test-constructor2_default", "test-cbor_all", "test-allocator_default", "test-testsuites_default", "test-to_chars_all", "test-allocator_all", "test-readme_all", "test-pointer_access_default", "test-msgpack_all", "test-regression_default", "test-conversions_default", "test-wstring_all", "test-readme_default", "test-noexcept_default", "test-class_iterator_default", "test-algorithms_default", "test-alt-string_all", "test-alt-string_default", "test-items_default", "cmake_import_minver_configure", "test-merge_patch_default", "test-constructor1_default", "test-cbor_default", "test-iterators1_default", "test-udt_default", "test-reference_access_all", "test-capacity_default", "test-meta_default", "cmake_add_subdirectory_build", "test-json_pointer_default", "test-bson_all", "test-modifiers_all", "test-constructor1_all", "cmake_import_build", "test-class_lexer_default", "test-class_iterator_all", "test-inspection_all", "test-algorithms_all", "test-comparison_all", "test-constructor2_all", "test-meta_all", "test-concepts_all", "test-unicode_default", "test-serialization_all", "test-msgpack_default", "test-convenience_all", "test-class_parser_default", "test-element_access1_all", "test-element_access1_default", "test-inspection_default", "test-bson_default", "test-unicode_all", "test-conversions_all", "test-noexcept_all", "test-concepts_default", "test-iterators2_all", "test-pointer_access_all", "test-iterators1_all", "test-modifiers_default", "test-json_patch_all", "test-to_chars_default", "test-capacity_all", "test-element_access2_all", "test-ubjson_all", "test-serialization_default", "test-testsuites_all", "test-class_lexer_all", "test-json_patch_default", "test-json_pointer_all", "test-class_parser_all", "test-merge_patch_all", "test-iterators2_default", "cmake_import_configure", "test-deserialization_all", "test-ubjson_default", "test-convenience_default", "test-deserialization_default"], "failed_tests": [], "skipped_tests": []}