📝 document future behavior change
This commit is contained in:
parent
a8ee44df41
commit
063a288a87
@ -27,33 +27,44 @@ Linear in the size of the JSON value.
|
||||
|
||||
## Notes
|
||||
|
||||
By default `JSON_EXPLICIT` defined to the empty string, so the signature is:
|
||||
!!! note "Definition of `JSON_EXPLICIT`"
|
||||
|
||||
```cpp
|
||||
template<typename ValueType>
|
||||
operator ValueType() const;
|
||||
```
|
||||
By default `JSON_EXPLICIT` defined to the empty string, so the signature is:
|
||||
|
||||
```cpp
|
||||
template<typename ValueType>
|
||||
operator ValueType() const;
|
||||
```
|
||||
|
||||
If [`JSON_USE_IMPLICIT_CONVERSIONS`](../macros/json_use_implicit_conversions.md) is set to `0`,
|
||||
`JSON_EXPLICIT` is defined to `#!cpp explicit`:
|
||||
|
||||
If [`JSON_USE_IMPLICIT_CONVERSIONS`](../../features/macros.md#json_use_implicit_conversions) is set to `0`,
|
||||
`JSON_EXPLICIT` is defined to `#!cpp explicit`:
|
||||
```cpp
|
||||
template<typename ValueType>
|
||||
explicit operator ValueType() const;
|
||||
```
|
||||
|
||||
That is, implicit conversions can be switched off by defining
|
||||
[`JSON_USE_IMPLICIT_CONVERSIONS`](../macros/json_use_implicit_conversions.md) to `0`.
|
||||
|
||||
```cpp
|
||||
template<typename ValueType>
|
||||
explicit operator ValueType() const;
|
||||
```
|
||||
!!! info "Future behavior change"
|
||||
|
||||
Implicit conversions will be switched off by default in the next major release of the library. That is,
|
||||
`JSON_EXPLICIT` will be set to `#!cpp explicit` by default.
|
||||
|
||||
You can prepare existing code by already defining
|
||||
[`JSON_USE_IMPLICIT_CONVERSIONS`](../macros/json_use_implicit_conversions.md) to `0` and adjust any implicit
|
||||
conversions by calls to [`get`](../basic_json/get.md).
|
||||
|
||||
That is, implicit conversions can be switched off by defining
|
||||
[`JSON_USE_IMPLICIT_CONVERSIONS`](../../features/macros.md#json_use_implicit_conversions) to `0`.
|
||||
|
||||
## Examples
|
||||
|
||||
??? example
|
||||
|
||||
The example below shows several conversions from JSON values
|
||||
to other types. There a few things to note: (1) Floating-point numbers can
|
||||
be converted to integers, (2) A JSON array can be converted to a standard
|
||||
`std::vector<short>`, (3) A JSON object can be converted to C++
|
||||
associative containers such as `std::unordered_map<std::string, json>`.
|
||||
The example below shows several conversions from JSON values to other types. There a few things to note: (1)
|
||||
Floating-point numbers can be converted to integers, (2) A JSON array can be converted to a standard
|
||||
`std::vector<short>`, (3) A JSON object can be converted to C++ associative containers such as
|
||||
`std::unordered_map<std::string, json>`.
|
||||
|
||||
```cpp
|
||||
--8<-- "examples/operator__ValueType.cpp"
|
||||
|
||||
@ -4,7 +4,8 @@
|
||||
#define JSON_USE_IMPLICIT_CONVERSIONS /* value */
|
||||
```
|
||||
|
||||
When defined to `0`, implicit conversions are switched off. By default, implicit conversions are switched on.
|
||||
When defined to `0`, implicit conversions are switched off. By default, implicit conversions are switched on. The
|
||||
value is directly affecting [`operator ValueType`](../basic_json/operator_ValueType.md).
|
||||
|
||||
Implicit conversions can also be controlled with the CMake option `JSON_ImplicitConversions` (`ON` by default) which
|
||||
sets `JSON_USE_IMPLICIT_CONVERSIONS` accordingly.
|
||||
@ -17,6 +18,15 @@ By default, implicit conversions are enabled.
|
||||
#define JSON_USE_IMPLICIT_CONVERSIONS 1
|
||||
```
|
||||
|
||||
## Notes
|
||||
|
||||
!!! info "Future behavior change"
|
||||
|
||||
Implicit conversions will be switched off by default in the next major release of the library.
|
||||
|
||||
You can prepare existing code by already defining `JSON_USE_IMPLICIT_CONVERSIONS` to `0` and adjust any implicit
|
||||
conversions by calls to [`get`](../basic_json/get.md).
|
||||
|
||||
## Examples
|
||||
|
||||
??? example
|
||||
@ -36,6 +46,11 @@ By default, implicit conversions are enabled.
|
||||
auto s = j.get<std::string>();
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
- [**operator ValueType**](../basic_json/operator_ValueType.md) - get a value (implicit)
|
||||
- [**get**](../basic_json/get.md) - get a value (explicit)
|
||||
|
||||
## Version history
|
||||
|
||||
- Added in version 3.9.0.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user