Use template get instead of get in examples (#4039)

Co-authored-by: tusooa <tusooa@kazv.moe>
This commit is contained in:
No
2023-06-11 04:06:24 -04:00
committed by GitHub
parent 793878898f
commit c71ecde505
23 changed files with 80 additions and 80 deletions
@@ -37,7 +37,7 @@ Copy of the JSON value, converted to `ValueType`
??? example "Example: (1) Default-constructible type"
The example below shows how a `from_json` function can be implemented for a user-defined type. This function is
called by the `adl_serializer` when `get<ns::person>()` is called.
called by the `adl_serializer` when `template get<ns::person>()` is called.
```cpp
--8<-- "examples/from_json__default_constructible.cpp"
@@ -53,7 +53,7 @@ The default value is `0`.
const json j = Choice::first;
// normally invokes from_json parse function but with JSON_DISABLE_ENUM_SERIALIZATION defined, it does not
Choice ch = j.get<Choice>();
Choice ch = j.template get<Choice>();
}
```
@@ -86,7 +86,7 @@ The default value is `0`.
const json j = Choice::first;
// uses user-defined from_json function defined by macro
Choice ch = j.get<Choice>();
Choice ch = j.template get<Choice>();
}
```
@@ -109,7 +109,7 @@ The default value is `0`.
void from_json(const json& j, Choice& ch)
{
auto value = j.get<std::string>();
auto value = j.template get<std::string>();
if (value == "first")
{
ch = Choice::first;
@@ -122,7 +122,7 @@ The default value is `0`.
void to_json(json& j, const Choice& ch)
{
auto value = j.get<std::string>();
auto value = j.template get<std::string>();
if (value == "first")
{
ch = Choice::first;
@@ -139,7 +139,7 @@ The default value is `0`.
const json j = Choice::first;
// uses user-defined from_json function
Choice ch = j.get<Choice>();
Choice ch = j.template get<Choice>();
}
```
@@ -46,7 +46,7 @@ By default, implicit conversions are enabled.
```cpp
json j = "Hello, world!";
auto s = j.get<std::string>();
auto s = j.template get<std::string>();
```
## See also
@@ -37,7 +37,7 @@ inline void from_json(const BasicJsonType& j, type& e);
!!! important "Important notes"
- When using [`get<ENUM_TYPE>()`](../basic_json/get.md), undefined JSON values will default to the first specified
- When using [`template get<ENUM_TYPE>()`](../basic_json/get.md), undefined JSON values will default to the first specified
conversion. Select this default pair carefully. See example 1 below.
- If an enum or JSON value is specified in multiple conversions, the first matching conversion from the top of the
list will be returned when converting to or from JSON. See example 2 below.