json/docs/mkdocs/docs/api/macros/json_use_implicit_conversions.md
Florian Albrechtskirchinger d3e347bd2d
More documentation updates for 3.11.0 (#3553)
* mkdocs: add string_view examples

* mkdocs: reference underlying operators

* mkdocs: add operator<=> examples

* mkdocs: fix style check issues

* mkdocs: tweak BJData page

* mkdocs: add CMake option hints to macros

* mkdocs: fix JSON_DISABLE_ENUM_SERIALIZATION definition

* mkdocs: fix link to unit-udt.cpp

* mkdocs: fix "Arbitrary Type Conversions" title

* mkdocs: link to api/macros/*.md instead of features/macros.md

* mkdocs: document JSON_DisableEnumSerialization CMake option

* mkdocs: encode required C++ standard in example files

* docset: detect gsed/sed

* docset: update index

* docset: fix CSS patching

* docset: add list_missing_pages make target

* docset: add list_removed_paths make target

* docset: replace page titles with name from index

* docset: add install target for Zeal docset browser

* Use GCC_TOOL in ci_test_documentation target
2022-07-31 14:05:58 +02:00

1.6 KiB

JSON_USE_IMPLICIT_CONVERSIONS

#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.

Default definition

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 replace any implicit
conversions with calls to [`get`](../basic_json/get.md).

!!! hint "CMake option"

Implicit conversions can also be controlled with the CMake option
[`JSON_ImplicitConversions`](../../integration/cmake.md#json_legacydiscardedvaluecomparison)
(`ON` by default) which defines `JSON_USE_IMPLICIT_CONVERSIONS` accordingly.

Examples

??? example

This is an example for an implicit conversion:

```cpp
json j = "Hello, world!";
std::string s = j;
```

When `JSON_USE_IMPLICIT_CONVERSIONS` is defined to `0`, the code above does no longer compile. Instead, it must be
written like this:

```cpp
json j = "Hello, world!";
auto s = j.get<std::string>();
```

See also

Version history

  • Added in version 3.9.0.