- Copying is disabled because of its cost, not because of two documents borrowing the same buffer; the unique_ptr follows from move-only. - Inputs: streams, FILE*, and wide characters (strings, arrays, pointers) are all supported and owned; point to parse_copy() for owned copies. - The error replay only runs for failing input, builds no values, and is skipped with allow_exceptions = false. - read() writes copied inputs into the previous owned copy. - Views can dangle like std::string_view, and why there is no shared/weak pointer design. - The 4 GiB limit (16-byte nodes, 16-byte scanner steps), streams being read to the end first, which macros apply, why materialize() has no source positions, and wording nits (accept() vs basic_json::accept(), is_binary, is_discarded, see-also lists, size table, "back into"). Signed-off-by: Niels Lohmann <mail@nlohmann.me>
1.2 KiB
1.2 KiB
nlohmann::basic_json_document::owns_source
bool owns_source() const noexcept;
Returns whether the document holds its own copy of the parsed text or is borrowing the caller's buffer.
Return value
#!cpp true if the document owns the text returned by source(), #!cpp false if it borrows it (or if
the document is discarded).
Exception safety
No-throw guarantee: this function never throws exceptions.
Complexity
Constant.
Notes
See the ownership table on parse for which inputs are borrowed and which are owned. A borrowed
document (#!cpp owns_source() == false) is only valid while the buffer it was parsed from is still alive.
Examples
??? example
```cpp
--8<-- "examples/basic_json_document__owns_source.cpp"
```
Output:
```json
--8<-- "examples/basic_json_document__owns_source.output"
```
See also
- parse - deserialize from a compatible input
- parse_copy - deserialize a copy of a compatible input, always owned
- source - the parsed text
Version history
- Added in version 3.13.0.