Skip to content

Commit a6d937c

Browse files
committed
Update documentation and examples with restricted BasicJsonType
Signed-off-by: kimci86 <[email protected]>
1 parent 5d3d8fa commit a6d937c

9 files changed

+22
-22
lines changed

docs/mkdocs/docs/api/macros/nlohmann_define_derived_type.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,25 +64,25 @@ Summary:
6464
Macros 1 and 2 add two friend functions to the class which take care of the serialization and deserialization:
6565

6666
```cpp
67-
template<typename BasicJsonType>
67+
template<typename BasicJsonType, nlohmann::detail::enable_if_t<nlohmann::detail::is_basic_json<BasicJsonType>::value, int> = 0>
6868
friend void to_json(BasicJsonType&, const type&);
69-
template<typename BasicJsonType>
69+
template<typename BasicJsonType, nlohmann::detail::enable_if_t<nlohmann::detail::is_basic_json<BasicJsonType>::value, int> = 0>
7070
friend void from_json(const BasicJsonType&, type&);
7171
```
7272
7373
Macros 4 and 5 add two functions to the namespace which take care of the serialization and deserialization:
7474
7575
```cpp
76-
template<typename BasicJsonType>
76+
template<typename BasicJsonType, nlohmann::detail::enable_if_t<nlohmann::detail::is_basic_json<BasicJsonType>::value, int> = 0>
7777
void to_json(BasicJsonType&, const type&);
78-
template<typename BasicJsonType>
78+
template<typename BasicJsonType, nlohmann::detail::enable_if_t<nlohmann::detail::is_basic_json<BasicJsonType>::value, int> = 0>
7979
void from_json(const BasicJsonType&, type&);
8080
```
8181

8282
Macros 3 and 6 add one function to the namespace which take care of the serialization only:
8383

8484
```cpp
85-
template<typename BasicJsonType>
85+
template<typename BasicJsonType, nlohmann::detail::enable_if_t<nlohmann::detail::is_basic_json<BasicJsonType>::value, int> = 0>
8686
void to_json(BasicJsonType&, const type&);
8787
```
8888
@@ -93,13 +93,13 @@ before serializing/deserializing the members of the derived type:
9393
class A { /* ... */ };
9494
class B : public A { /* ... */ };
9595
96-
template<typename BasicJsonType>
96+
template<typename BasicJsonType, nlohmann::detail::enable_if_t<nlohmann::detail::is_basic_json<BasicJsonType>::value, int> = 0>
9797
void to_json(BasicJsonType& j, const B& b) {
9898
nlohmann::to_json(j, static_cast<const A&>(b));
9999
// ...
100100
}
101101
102-
template<typename BasicJsonType>
102+
template<typename BasicJsonType, nlohmann::detail::enable_if_t<nlohmann::detail::is_basic_json<BasicJsonType>::value, int> = 0>
103103
void from_json(const BasicJsonType& j, B& b) {
104104
nlohmann::from_json(j, static_cast<A&>(b));
105105
// ...
@@ -112,7 +112,7 @@ In the third case, only `to_json` will be called:
112112
class A { /* ... */ };
113113
class B : public A { /* ... */ };
114114

115-
template<typename BasicJsonType>
115+
template<typename BasicJsonType, nlohmann::detail::enable_if_t<nlohmann::detail::is_basic_json<BasicJsonType>::value, int> = 0>
116116
void to_json(BasicJsonType& j, const B& b) {
117117
nlohmann::to_json(j, static_cast<const A&>(b));
118118
// ...

docs/mkdocs/docs/api/macros/nlohmann_define_type_intrusive.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ Summary:
4040
The macros add two friend functions to the class which take care of the serialization and deserialization:
4141
4242
```cpp
43-
template<typename BasicJsonType>
43+
template<typename BasicJsonType, nlohmann::detail::enable_if_t<nlohmann::detail::is_basic_json<BasicJsonType>::value, int> = 0>
4444
friend void to_json(BasicJsonType&, const type&);
45-
template<typename BasicJsonType>
45+
template<typename BasicJsonType, nlohmann::detail::enable_if_t<nlohmann::detail::is_basic_json<BasicJsonType>::value, int> = 0>
4646
friend void from_json(const BasicJsonType&, type&); // except (3)
4747
```
4848

docs/mkdocs/docs/api/macros/nlohmann_define_type_non_intrusive.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ Summary:
4040
The macros add two functions to the namespace which take care of the serialization and deserialization:
4141
4242
```cpp
43-
template<typename BasicJsonType>
43+
template<typename BasicJsonType, nlohmann::detail::enable_if_t<nlohmann::detail::is_basic_json<BasicJsonType>::value, int> = 0>
4444
void to_json(BasicJsonType&, const type&);
45-
template<typename BasicJsonType>
45+
template<typename BasicJsonType, nlohmann::detail::enable_if_t<nlohmann::detail::is_basic_json<BasicJsonType>::value, int> = 0>
4646
void from_json(const BasicJsonType&, type&); // except (3)
4747
```
4848

docs/mkdocs/docs/examples/nlohmann_define_type_intrusive_explicit.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ class person
1919
: name(std::move(name_)), address(std::move(address_)), age(age_)
2020
{}
2121

22-
template<typename BasicJsonType>
22+
template<typename BasicJsonType, nlohmann::detail::enable_if_t<nlohmann::detail::is_basic_json<BasicJsonType>::value, int> = 0>
2323
friend void to_json(BasicJsonType& nlohmann_json_j, const person& nlohmann_json_t)
2424
{
2525
nlohmann_json_j["name"] = nlohmann_json_t.name;
2626
nlohmann_json_j["address"] = nlohmann_json_t.address;
2727
nlohmann_json_j["age"] = nlohmann_json_t.age;
2828
}
2929

30-
template<typename BasicJsonType>
30+
template<typename BasicJsonType, nlohmann::detail::enable_if_t<nlohmann::detail::is_basic_json<BasicJsonType>::value, int> = 0>
3131
friend void from_json(const BasicJsonType& nlohmann_json_j, person& nlohmann_json_t)
3232
{
3333
nlohmann_json_t.name = nlohmann_json_j.at("name");

docs/mkdocs/docs/examples/nlohmann_define_type_intrusive_only_serialize_explicit.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class person
1919
: name(std::move(name_)), address(std::move(address_)), age(age_)
2020
{}
2121

22-
template<typename BasicJsonType>
22+
template<typename BasicJsonType, nlohmann::detail::enable_if_t<nlohmann::detail::is_basic_json<BasicJsonType>::value, int> = 0>
2323
friend void to_json(BasicJsonType& nlohmann_json_j, const person& nlohmann_json_t)
2424
{
2525
nlohmann_json_j["name"] = nlohmann_json_t.name;

docs/mkdocs/docs/examples/nlohmann_define_type_intrusive_with_default_explicit.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ class person
1919
: name(std::move(name_)), address(std::move(address_)), age(age_)
2020
{}
2121

22-
template<typename BasicJsonType>
22+
template<typename BasicJsonType, nlohmann::detail::enable_if_t<nlohmann::detail::is_basic_json<BasicJsonType>::value, int> = 0>
2323
friend void to_json(BasicJsonType& nlohmann_json_j, const person& nlohmann_json_t)
2424
{
2525
nlohmann_json_j["name"] = nlohmann_json_t.name;
2626
nlohmann_json_j["address"] = nlohmann_json_t.address;
2727
nlohmann_json_j["age"] = nlohmann_json_t.age;
2828
}
2929

30-
template<typename BasicJsonType>
30+
template<typename BasicJsonType, nlohmann::detail::enable_if_t<nlohmann::detail::is_basic_json<BasicJsonType>::value, int> = 0>
3131
friend void from_json(const BasicJsonType& nlohmann_json_j, person& nlohmann_json_t)
3232
{
3333
person nlohmann_json_default_obj;

docs/mkdocs/docs/examples/nlohmann_define_type_non_intrusive_explicit.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ struct person
1313
int age;
1414
};
1515

16-
template<typename BasicJsonType>
16+
template<typename BasicJsonType, nlohmann::detail::enable_if_t<nlohmann::detail::is_basic_json<BasicJsonType>::value, int> = 0>
1717
void to_json(BasicJsonType& nlohmann_json_j, const person& nlohmann_json_t)
1818
{
1919
nlohmann_json_j["name"] = nlohmann_json_t.name;
2020
nlohmann_json_j["address"] = nlohmann_json_t.address;
2121
nlohmann_json_j["age"] = nlohmann_json_t.age;
2222
}
2323

24-
template<typename BasicJsonType>
24+
template<typename BasicJsonType, nlohmann::detail::enable_if_t<nlohmann::detail::is_basic_json<BasicJsonType>::value, int> = 0>
2525
void from_json(const BasicJsonType& nlohmann_json_j, person& nlohmann_json_t)
2626
{
2727
nlohmann_json_t.name = nlohmann_json_j.at("name");

docs/mkdocs/docs/examples/nlohmann_define_type_non_intrusive_only_serialize_explicit.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ struct person
1313
int age;
1414
};
1515

16-
template<typename BasicJsonType>
16+
template<typename BasicJsonType, nlohmann::detail::enable_if_t<nlohmann::detail::is_basic_json<BasicJsonType>::value, int> = 0>
1717
void to_json(BasicJsonType& nlohmann_json_j, const person& nlohmann_json_t)
1818
{
1919
nlohmann_json_j["name"] = nlohmann_json_t.name;

docs/mkdocs/docs/examples/nlohmann_define_type_non_intrusive_with_default_explicit.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ struct person
1818
{}
1919
};
2020

21-
template<typename BasicJsonType>
21+
template<typename BasicJsonType, nlohmann::detail::enable_if_t<nlohmann::detail::is_basic_json<BasicJsonType>::value, int> = 0>
2222
void to_json(BasicJsonType& nlohmann_json_j, const person& nlohmann_json_t)
2323
{
2424
nlohmann_json_j["name"] = nlohmann_json_t.name;
2525
nlohmann_json_j["address"] = nlohmann_json_t.address;
2626
nlohmann_json_j["age"] = nlohmann_json_t.age;
2727
}
2828

29-
template<typename BasicJsonType>
29+
template<typename BasicJsonType, nlohmann::detail::enable_if_t<nlohmann::detail::is_basic_json<BasicJsonType>::value, int> = 0>
3030
void from_json(const BasicJsonType& nlohmann_json_j, person& nlohmann_json_t)
3131
{
3232
person nlohmann_json_default_obj;

0 commit comments

Comments
 (0)