Add automatic rewind for at_pointer
`at_pointer` now automatically rewinds each call (as per #1622). The rewind is done at the beginning of the call, before any parsing is done. This is something we would want to mention in the documentation. Furthermore, it will also be important to mention to the user that `rewind` invalidates certain values (objects/arrays), and so it is important to store/consume them independently between each call of `at_pointer` which rewinds automatically now. This PR just implements the automatic rewind feature, the documentation issue will be fixed by #1618.

Fixes #1622
{"label": "simdjson:master", "ref": "master", "sha": "6cd04aa858f2d92105c0fbd65cdafb96428db002"}
Currently, users of the On Demand API who use at_pointer (JSON Pointer) have to manually rewind.

Why don't we make that automatic?
at_pointer in On Demand should automatically rewind
diff --git a/include/simdjson/generic/ondemand/array.h b/include/simdjson/generic/ondemand/array.h
index 27d06078c6..28fa8b6624 100644
--- a/include/simdjson/generic/ondemand/array.h
+++ b/include/simdjson/generic/ondemand/array.h
@@ -54,7 +54,7 @@ class array {
    *   auto doc = parser.iterate(json);
    *   doc.at_pointer("/0/foo/a/1") == 20
    *
-   * Note that at_pointer() does not automatically rewind between each call (call rewind() to reset).
+   * Note that at_pointer() automatically calls rewind between each call.
    * Also note that at_pointer() relies on find_field() which implies that we do not unescape keys when matching.
    * @return The value associated with the given JSON pointer, or:
    *         - NO_SUCH_FIELD if a field does not exist in an object
diff --git a/include/simdjson/generic/ondemand/document-inl.h b/include/simdjson/generic/ondemand/document-inl.h
index fc158694a8..75b0cd295f 100644
--- a/include/simdjson/generic/ondemand/document-inl.h
+++ b/include/simdjson/generic/ondemand/document-inl.h
@@ -135,6 +135,7 @@ simdjson_really_inline simdjson_result<std::string_view> document::raw_json_toke
 }
 
 simdjson_really_inline simdjson_result<value> document::at_pointer(std::string_view json_pointer) noexcept {
+  rewind(); // Rewind the document each time at_pointer is called
   if (json_pointer.empty()) {
     return this->resume_value();
   }
diff --git a/include/simdjson/generic/ondemand/document.h b/include/simdjson/generic/ondemand/document.h
index edc269484e..9abcd73896 100644
--- a/include/simdjson/generic/ondemand/document.h
+++ b/include/simdjson/generic/ondemand/document.h
@@ -335,7 +335,7 @@ class document {
    *   auto doc = parser.iterate(json);
    *   doc.at_pointer("//a/1") == 20
    *
-   * Note that at_pointer() does not automatically rewind between each call (call rewind() to reset).
+   * Note that at_pointer() automatically calls rewind between each call.
    * Also note that at_pointer() relies on find_field() which implies that we do not unescape keys when matching
    *
    * @return The value associated with the given JSON pointer, or:
diff --git a/include/simdjson/generic/ondemand/object.h b/include/simdjson/generic/ondemand/object.h
index 2eb71c977f..c92bbf79db 100644
--- a/include/simdjson/generic/ondemand/object.h
+++ b/include/simdjson/generic/ondemand/object.h
@@ -91,7 +91,7 @@ class object {
    *   auto doc = parser.iterate(json);
    *   doc.at_pointer("//a/1") == 20
    *
-   * Note that at_pointer() does not automatically rewind between each call (call rewind() to reset).
+   * Note that at_pointer() automatically calls rewind between each call.
    * Also note that at_pointer() relies on find_field() which implies that we do not unescape keys when matching.
    *
    * @return The value associated with the given JSON pointer, or:
diff --git a/include/simdjson/generic/ondemand/value.h b/include/simdjson/generic/ondemand/value.h
index 631c254f1a..e2b092e79f 100644
--- a/include/simdjson/generic/ondemand/value.h
+++ b/include/simdjson/generic/ondemand/value.h
@@ -330,7 +330,7 @@ class value {
    *   auto doc = parser.iterate(json);
    *   doc.at_pointer("//a/1") == 20
    *
-   * Note that at_pointer() does not automatically rewind between each call (call rewind() to reset).
+   * Note that at_pointer() automatically calls rewind between each call.
    * Also note that at_pointer() relies on find_field() which implies that we do not unescape keys when matching
    *
    * @return The value associated with the given JSON pointer, or:

diff --git a/tests/ondemand/ondemand_json_pointer_tests.cpp b/tests/ondemand/ondemand_json_pointer_tests.cpp
index 9ee29454ad..ac79716aac 100644
--- a/tests/ondemand/ondemand_json_pointer_tests.cpp
+++ b/tests/ondemand/ondemand_json_pointer_tests.cpp
@@ -117,7 +117,6 @@ namespace json_pointer_tests {
             std::string json_pointer = "/" + std::to_string(i) + "/tire_pressure/1";
             ASSERT_SUCCESS(cars.at_pointer(json_pointer).get(x));
             measured.push_back(x);
-            cars.rewind();
         }
 
         std::vector<double> expected = {39.9, 31, 30};

{"ondemand_json_pointer_tests": {"run": "PASS", "test": "NONE", "fix": "PASS"}}
{"readme_examples11": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "iterate_temporary_buffer_should_not_compile": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "ondemand_array_tests": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "quickstart_ondemand": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "ondemand_scalar_tests": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "unicode_tests": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "readme_examples_will_fail_with_exceptions_off": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "ondemand_twitter_tests": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "document_stream_tests": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "random_string_number_tests": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "dangling_parser_parse_uint8_should_not_compile": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "readme_examples": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "dangling_parser_load_should_not_compile": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "quickstart_ondemand11": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "iterate_string_view_should_not_compile": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "ondemand_wrong_type_error_tests": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "ondemand_misc_tests": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "ondemand_ordering_tests": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "iterate_char_star_should_not_compile": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "minefieldcheck": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "stringparsingcheck": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "basictests": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "ondemand_number_tests": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "dangling_parser_parse_padstring_should_compile": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "ondemand_array_error_tests": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "quickstart2_noexceptions": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "quickstart_ondemand14": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "ondemand_readme_examples": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "quickstart2_noexceptions11": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "errortests": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "quickstart14": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "avoid_cerr": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "dangling_parser_parse_uchar_should_compile": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "trivially_copyable_test": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "avoid_printf": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "ondemand_parse_api_tests": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "iterate_char_star_should_compile": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "readme_examples_noexceptions": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "simdjson_force_implementation_error": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "parse_many_test": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "dangling_parser_parse_uint8_should_compile": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "checkimplementation": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "quickstart_noexceptions11": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "ondemand_compilation_tests": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "avoid_stdout": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "unsafe_parse_many_should_compile": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "avoid_cout": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "ondemand_active_tests": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "example_compiletest_should_compile": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "dangling_parser_parse_uchar_should_not_compile": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "jsoncheck": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "avoid_stderr": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "extracting_values_example": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "simdjson-singleheader": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "ondemand_error_tests": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "dangling_parser_parse_stdstring_should_not_compile": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "pointercheck": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "ondemand_object_tests": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "integer_tests": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "minify_tests": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "quickstart_ondemand_noexceptions": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "quickstart11": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "quickstart": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "testjson2json": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "document_tests": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "example_compiletest_should_not_compile": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "padded_string_tests": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "json2json": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "ondemand_assert_out_of_order_values": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "ondemand_key_string_tests": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "bad_array_count_should_compile": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "avoid_abort": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "quickstart_ondemand_noexceptions11": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "dangling_parser_load_should_compile": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "numberparsingcheck": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "readme_examples_noexceptions11": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "quickstart_noexceptions": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "amalgamate_demo_direct_from_repository": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "ondemand_tostring_tests": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "unsafe_parse_many_should_not_compile": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "dangling_parser_parse_stdstring_should_compile": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "iterate_string_view_should_compile": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "iterate_temporary_buffer_should_compile": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "amalgamate_demo": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "dangling_parser_parse_padstring_should_not_compile": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "bad_array_count_should_not_compile": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "ondemand_object_error_tests": {"run": "PASS", "test": "PASS", "fix": "PASS"}}
{"ondemand_json_pointer_tests": {"run": "PASS", "test": "NONE", "fix": "PASS"}}
{"passed_count": 88, "failed_count": 0, "skipped_count": 0, "passed_tests": ["ondemand_array_tests", "unicode_tests", "readme_examples_will_fail_with_exceptions_off", "ondemand_twitter_tests", "document_stream_tests", "random_string_number_tests", "dangling_parser_parse_uint8_should_not_compile", "quickstart_ondemand11", "iterate_string_view_should_not_compile", "ondemand_misc_tests", "minefieldcheck", "ondemand_number_tests", "dangling_parser_parse_padstring_should_compile", "ondemand_array_error_tests", "quickstart_ondemand14", "ondemand_readme_examples", "quickstart14", "dangling_parser_parse_uchar_should_compile", "iterate_char_star_should_compile", "readme_examples_noexceptions", "ondemand_json_pointer_tests", "dangling_parser_parse_uint8_should_compile", "checkimplementation", "quickstart_noexceptions11", "ondemand_compilation_tests", "avoid_stdout", "unsafe_parse_many_should_compile", "avoid_cout", "ondemand_active_tests", "example_compiletest_should_compile", "dangling_parser_parse_uchar_should_not_compile", "jsoncheck", "ondemand_error_tests", "pointercheck", "ondemand_object_tests", "quickstart_ondemand_noexceptions", "quickstart11", "quickstart", "testjson2json", "bad_array_count_should_compile", "readme_examples_noexceptions11", "ondemand_tostring_tests", "unsafe_parse_many_should_not_compile", "dangling_parser_parse_stdstring_should_compile", "iterate_string_view_should_compile", "amalgamate_demo", "dangling_parser_parse_padstring_should_not_compile", "ondemand_object_error_tests", "readme_examples11", "iterate_temporary_buffer_should_not_compile", "quickstart_ondemand", "ondemand_scalar_tests", "readme_examples", "dangling_parser_load_should_not_compile", "ondemand_wrong_type_error_tests", "ondemand_ordering_tests", "iterate_char_star_should_not_compile", "stringparsingcheck", "basictests", "quickstart2_noexceptions", "quickstart2_noexceptions11", "errortests", "avoid_cerr", "trivially_copyable_test", "avoid_printf", "ondemand_parse_api_tests", "simdjson_force_implementation_error", "parse_many_test", "avoid_stderr", "extracting_values_example", "simdjson-singleheader", "dangling_parser_parse_stdstring_should_not_compile", "integer_tests", "minify_tests", "document_tests", "example_compiletest_should_not_compile", "padded_string_tests", "json2json", "ondemand_assert_out_of_order_values", "ondemand_key_string_tests", "avoid_abort", "quickstart_ondemand_noexceptions11", "dangling_parser_load_should_compile", "numberparsingcheck", "quickstart_noexceptions", "amalgamate_demo_direct_from_repository", "iterate_temporary_buffer_should_compile", "bad_array_count_should_not_compile"], "failed_tests": [], "skipped_tests": []}
{"passed_count": 87, "failed_count": 0, "skipped_count": 0, "passed_tests": ["ondemand_array_tests", "unicode_tests", "readme_examples_will_fail_with_exceptions_off", "ondemand_twitter_tests", "document_stream_tests", "random_string_number_tests", "dangling_parser_parse_uint8_should_not_compile", "quickstart_ondemand11", "iterate_string_view_should_not_compile", "ondemand_misc_tests", "minefieldcheck", "ondemand_number_tests", "dangling_parser_parse_padstring_should_compile", "ondemand_array_error_tests", "quickstart_ondemand14", "ondemand_readme_examples", "quickstart14", "dangling_parser_parse_uchar_should_compile", "iterate_char_star_should_compile", "readme_examples_noexceptions", "dangling_parser_parse_uint8_should_compile", "checkimplementation", "quickstart_noexceptions11", "ondemand_compilation_tests", "avoid_stdout", "unsafe_parse_many_should_compile", "avoid_cout", "ondemand_active_tests", "example_compiletest_should_compile", "dangling_parser_parse_uchar_should_not_compile", "jsoncheck", "ondemand_error_tests", "pointercheck", "ondemand_object_tests", "quickstart_ondemand_noexceptions", "quickstart11", "quickstart", "testjson2json", "bad_array_count_should_compile", "readme_examples_noexceptions11", "ondemand_tostring_tests", "unsafe_parse_many_should_not_compile", "dangling_parser_parse_stdstring_should_compile", "iterate_string_view_should_compile", "amalgamate_demo", "dangling_parser_parse_padstring_should_not_compile", "ondemand_object_error_tests", "readme_examples11", "iterate_temporary_buffer_should_not_compile", "quickstart_ondemand", "ondemand_scalar_tests", "readme_examples", "dangling_parser_load_should_not_compile", "ondemand_wrong_type_error_tests", "ondemand_ordering_tests", "iterate_char_star_should_not_compile", "stringparsingcheck", "basictests", "quickstart2_noexceptions", "quickstart2_noexceptions11", "errortests", "avoid_cerr", "trivially_copyable_test", "avoid_printf", "ondemand_parse_api_tests", "simdjson_force_implementation_error", "parse_many_test", "avoid_stderr", "extracting_values_example", "simdjson-singleheader", "dangling_parser_parse_stdstring_should_not_compile", "integer_tests", "minify_tests", "document_tests", "example_compiletest_should_not_compile", "padded_string_tests", "json2json", "ondemand_assert_out_of_order_values", "ondemand_key_string_tests", "avoid_abort", "quickstart_ondemand_noexceptions11", "dangling_parser_load_should_compile", "numberparsingcheck", "quickstart_noexceptions", "amalgamate_demo_direct_from_repository", "iterate_temporary_buffer_should_compile", "bad_array_count_should_not_compile"], "failed_tests": [], "skipped_tests": []}
{"passed_count": 88, "failed_count": 0, "skipped_count": 0, "passed_tests": ["ondemand_array_tests", "unicode_tests", "readme_examples_will_fail_with_exceptions_off", "ondemand_twitter_tests", "document_stream_tests", "random_string_number_tests", "dangling_parser_parse_uint8_should_not_compile", "quickstart_ondemand11", "iterate_string_view_should_not_compile", "ondemand_misc_tests", "minefieldcheck", "ondemand_number_tests", "dangling_parser_parse_padstring_should_compile", "ondemand_array_error_tests", "quickstart_ondemand14", "ondemand_readme_examples", "quickstart14", "dangling_parser_parse_uchar_should_compile", "iterate_char_star_should_compile", "readme_examples_noexceptions", "ondemand_json_pointer_tests", "dangling_parser_parse_uint8_should_compile", "checkimplementation", "quickstart_noexceptions11", "ondemand_compilation_tests", "avoid_stdout", "unsafe_parse_many_should_compile", "avoid_cout", "ondemand_active_tests", "example_compiletest_should_compile", "dangling_parser_parse_uchar_should_not_compile", "jsoncheck", "ondemand_error_tests", "pointercheck", "ondemand_object_tests", "quickstart_ondemand_noexceptions", "quickstart11", "quickstart", "testjson2json", "bad_array_count_should_compile", "readme_examples_noexceptions11", "ondemand_tostring_tests", "unsafe_parse_many_should_not_compile", "dangling_parser_parse_stdstring_should_compile", "iterate_string_view_should_compile", "amalgamate_demo", "dangling_parser_parse_padstring_should_not_compile", "ondemand_object_error_tests", "readme_examples11", "iterate_temporary_buffer_should_not_compile", "quickstart_ondemand", "ondemand_scalar_tests", "readme_examples", "dangling_parser_load_should_not_compile", "ondemand_wrong_type_error_tests", "ondemand_ordering_tests", "iterate_char_star_should_not_compile", "stringparsingcheck", "basictests", "quickstart2_noexceptions", "quickstart2_noexceptions11", "errortests", "avoid_cerr", "trivially_copyable_test", "avoid_printf", "ondemand_parse_api_tests", "simdjson_force_implementation_error", "parse_many_test", "avoid_stderr", "extracting_values_example", "simdjson-singleheader", "dangling_parser_parse_stdstring_should_not_compile", "integer_tests", "minify_tests", "document_tests", "example_compiletest_should_not_compile", "padded_string_tests", "json2json", "ondemand_assert_out_of_order_values", "ondemand_key_string_tests", "avoid_abort", "quickstart_ondemand_noexceptions11", "dangling_parser_load_should_compile", "numberparsingcheck", "quickstart_noexceptions", "amalgamate_demo_direct_from_repository", "iterate_temporary_buffer_should_compile", "bad_array_count_should_not_compile"], "failed_tests": [], "skipped_tests": []}