• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# basic_json::get_ref
2
3```cpp
4template<typename ReferenceType>
5ReferenceType get_ref();
6
7template<typename ReferenceType>
8const ReferenceType get_ref() const;
9```
10
11Implicit reference access to the internally stored JSON value. No copies are made.
12
13## Template arguments
14
15`ReferenceType`
16:   reference type; must be a reference to [`array_t`](array_t.md), [`object_t`](object_t.md),
17    [`string_t`](string_t.md), [`boolean_t`](boolean_t.md), [`number_integer_t`](number_integer_t.md), or
18    [`number_unsigned_t`](number_unsigned_t.md), [`number_float_t`](number_float_t.md), or [`binary_t`](binary_t.md).
19    Enforced by static assertion.
20
21## Return value
22
23reference to the internally stored JSON value if the requested reference type fits to the JSON value; throws
24[`type_error.303`](../../home/exceptions.md#jsonexceptiontype_error303) otherwise
25
26## Exception safety
27
28Strong exception safety: if an exception occurs, the original value stays intact.
29
30## Exceptions
31
32Throws [`type_error.303`](../../home/exceptions.md#jsonexceptiontype_error303) if the requested reference type does not
33match the stored JSON value type; example: `"incompatible ReferenceType for get_ref, actual type is binary"`.
34
35## Complexity
36
37Constant.
38
39## Notes
40
41!!! warning
42
43    Writing data to the referee of the result yields an undefined state.
44
45## Example
46
47??? example
48
49    The example shows several calls to `get_ref()`.
50
51    ```cpp
52    --8<-- "examples/get_ref.cpp"
53    ```
54
55    Output:
56
57    ```json
58    --8<-- "examples/get_ref.output"
59    ```
60
61## Version history
62
63- Added in version 1.1.0.
64- Extended to binary types in version 3.8.0.
65