mirror of
https://github.com/nlohmann/json.git
synced 2026-10-29 03:55:21 +00:00
deploy: 4155e2938f
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
#include <iostream>
|
||||
#include <nlohmann/json_view.hpp>
|
||||
|
||||
using json_document = nlohmann::json_document;
|
||||
|
||||
json_document parse_from_temporary_buffer()
|
||||
{
|
||||
char buffer[] = R"({"a": 1})";
|
||||
// parse() would borrow `buffer`, which is about to go out of scope;
|
||||
// parse_copy() takes its own copy instead, so the returned document does
|
||||
// not depend on `buffer` afterward
|
||||
return json_document::parse_copy(buffer);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
std::cout << std::boolalpha;
|
||||
|
||||
json_document doc = parse_from_temporary_buffer();
|
||||
std::cout << doc.owns_source() << '\n';
|
||||
std::cout << doc.root().is_object() << '\n';
|
||||
}
|
||||
Reference in New Issue
Block a user