From 12cb8b62dede11aaa7e2e88cce09bbac00571067 Mon Sep 17 00:00:00 2001 From: lemire Date: Tue, 16 Jul 2024 19:59:31 +0000 Subject: [PATCH] deploy: acdbbab91689212dc216262ad9e4f4e25cc01bcc --- md_doc_basics.html | 21 +++++++++++++++++++++ navtreedata.js | 14 +++++++------- navtreeindex0.js | 14 +++++++------- navtreeindex1.js | 14 +++++++------- navtreeindex2.js | 14 +++++++------- navtreeindex3.js | 14 +++++++------- navtreeindex4.js | 18 +++++++++--------- navtreeindex5.js | 16 ++++++++-------- navtreeindex6.js | 14 +++++++------- 9 files changed, 80 insertions(+), 59 deletions(-) diff --git a/md_doc_basics.html b/md_doc_basics.html index 106c3ff77..65c198845 100644 --- a/md_doc_basics.html +++ b/md_doc_basics.html @@ -1958,6 +1958,27 @@ Examples
f(doc.get_array());
return EXIT_SUCCESS;
}
+ +
void example() {
+
ondemand::parser parser;
+
const padded_string json = R"({ "parent": {"child1": {"name": "John"} , "child2": {"name": "Daniel"}} })"_padded;
+
auto doc = parser.iterate(json);
+
ondemand::object parent = doc["parent"];
+
// parent owns the focus
+
ondemand::object c1 = parent["child1"];
+
// c1 owns the focus
+
//
+
std::string_view as1 = c1["name"];
+
// We have that as1 == "John", as long as 'parser' and 'json' live
+
// c2 attempts to grab the focus from parent but fails
+
ondemand::object c2 = parent["child2"];
+
// c2 owns the focus, at this point c1 is invalid
+
std::string_view as2 = c2["name"];
+
// We have that as2 == "Daniel", as long as 'parser' and 'json' live
+
std::cout << as1 << " " << as2 << std::endl; // prints John Daniel
+
}

Performance tips