mirror of
https://github.com/nlohmann/json.git
synced 2026-10-05 14:10:31 +00:00
deploy: d8d47be4a5
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
#define JSON_USE_IMPLICIT_CONVERSIONS /* value */
|
||||
```
|
||||
|
||||
When defined to `0`, implicit conversions are switched off. By default, implicit conversions are switched on. The value directly affects [`operator ValueType`](https://json.nlohmann.me/api/basic_json/operator_ValueType/index.md).
|
||||
When defined to `0`, implicit conversions are switched off. By default, implicit conversions are switched on. The value directly affects [`operator ValueType`](https://json.nlohmann.me/api/basic_json/operator_ValueType/index.md) and the [converting constructor](https://json.nlohmann.me/api/basic_json/basic_json/index.md) from a `basic_json` specialization with a different string type (overload 4).
|
||||
|
||||
## Default definition
|
||||
|
||||
@@ -34,7 +34,7 @@ Implicit conversions can also be controlled with the CMake option [`JSON_Implici
|
||||
|
||||
## Examples
|
||||
|
||||
Example
|
||||
Example: implicit conversion
|
||||
|
||||
This is an example for an implicit conversion:
|
||||
|
||||
@@ -50,6 +50,23 @@ json j = "Hello, world!";
|
||||
auto s = j.get<std::string>();
|
||||
```
|
||||
|
||||
Example: conversion between `basic_json` specializations
|
||||
|
||||
A `basic_json` specialization with a different string type is also no longer converted implicitly when `JSON_USE_IMPLICIT_CONVERSIONS` is defined to `0`:
|
||||
|
||||
```
|
||||
using wjson = nlohmann::basic_json<std::map, std::vector, std::wstring>;
|
||||
|
||||
void load(const nlohmann::json& j);
|
||||
|
||||
wjson wj = /* ... */;
|
||||
load(wj); // error: no implicit conversion
|
||||
load(nlohmann::json(wj)); // OK: explicit conversion
|
||||
load(wj.get<nlohmann::json>()); // OK: explicit conversion
|
||||
```
|
||||
|
||||
Specializations that share the same string type, such as `json` and `ordered_json`, remain implicitly convertible.
|
||||
|
||||
## See also
|
||||
|
||||
- [**operator ValueType**](https://json.nlohmann.me/api/basic_json/operator_ValueType/index.md) - get a value (implicit)
|
||||
@@ -59,3 +76,4 @@ auto s = j.get<std::string>();
|
||||
## Version history
|
||||
|
||||
- Added in version 3.9.0.
|
||||
- Also affects the conversion between `basic_json` specializations with different string types since version 3.13.0 unreleased.
|
||||
|
||||
Reference in New Issue
Block a user