mirror of
https://github.com/nlohmann/json.git
synced 2026-09-30 22:15:19 +00:00
- API pages for get, get_to, get_string, number_token, and value of basic_json_view; JSON pointer overloads of operator[], at, and contains; links both ways with the basic_json pages - the feature page describes which conversions copy nothing - the examples show when the view helps: strings without copies, numbers exactly as written, and paths into a large text Signed-off-by: Niels Lohmann <mail@nlohmann.me>
1.2 KiB
1.2 KiB
nlohmann::basic_json_view::get_to
template<typename T>
T& get_to(T& v) const;
Converts the value to T and assigns it to v. Equivalent to
v = get<T>();
return v;
Template parameters
T- the type to convert the value to
Parameters
v(out)- the variable to store the converted value in
Return value
v, allowing calls to chain
Exception safety
Strong exception safety: if an exception is thrown, v is not modified.
Exceptions
Whatever get<T>() throws for the same value and T.
Complexity
Whatever get<T>() has for the same T.
Examples
??? example
The example below reads several fields of a service configuration directly into existing variables, then uses
the returned reference to fold the `#!cpp host`/`#!cpp port` pair into a single string in the same expression.
```cpp
--8<-- "examples/basic_json_view__get_to.cpp"
```
Output:
```json
--8<-- "examples/basic_json_view__get_to.output"
```
See also
- get - convert the value to a given type
BasicJsonType::get_to- the corresponding function ofbasic_json
Version history
- Added in version 3.13.0.