Skip to content

Commit 2f2352d

Browse files
committed
docs: replace unnecessary .template get<...> with .get<...> in README & MkDocs (fixes #4825)
1 parent 867127c commit 2f2352d

19 files changed

+64
-64
lines changed

README.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ Note the difference between serialization and assignment:
345345
json j_string = "this is a string";
346346

347347
// retrieve the string value
348-
auto cpp_string = j_string.template get<std::string>();
348+
auto cpp_string = j_string.get<std::string>();
349349
// retrieve the string value (alternative when a variable already exists)
350350
std::string cpp_string2;
351351
j_string.get_to(cpp_string2);
@@ -354,7 +354,7 @@ j_string.get_to(cpp_string2);
354354
std::string serialized_string = j_string.dump();
355355

356356
// output of original string
357-
std::cout << cpp_string << " == " << cpp_string2 << " == " << j_string.template get<std::string>() << '\n';
357+
std::cout << cpp_string << " == " << cpp_string2 << " == " << j_string.get<std::string>() << '\n';
358358
// output of serialized value
359359
std::cout << j_string << " == " << serialized_string << std::endl;
360360
```
@@ -527,7 +527,7 @@ for (auto& element : j) {
527527
}
528528
529529
// getter/setter
530-
const auto tmp = j[0].template get<std::string>();
530+
const auto tmp = j[0].get<std::string>();
531531
j[1] = 42;
532532
bool foo = j.at(2);
533533
@@ -734,7 +734,7 @@ You can switch off implicit conversions by defining `JSON_USE_IMPLICIT_CONVERSIO
734734
// strings
735735
std::string s1 = "Hello, world!";
736736
json js = s1;
737-
auto s2 = js.template get<std::string>();
737+
auto s2 = js.get<std::string>();
738738
// NOT RECOMMENDED
739739
std::string s3 = js;
740740
std::string s4;
@@ -743,7 +743,7 @@ s4 = js;
743743
// Booleans
744744
bool b1 = true;
745745
json jb = b1;
746-
auto b2 = jb.template get<bool>();
746+
auto b2 = jb.get<bool>();
747747
// NOT RECOMMENDED
748748
bool b3 = jb;
749749
bool b4;
@@ -752,7 +752,7 @@ b4 = jb;
752752
// numbers
753753
int i = 42;
754754
json jn = i;
755-
auto f = jn.template get<double>();
755+
auto f = jn.get<double>();
756756
// NOT RECOMMENDED
757757
double f2 = jb;
758758
double f3;
@@ -795,9 +795,9 @@ j["age"] = p.age;
795795

796796
// convert from JSON: copy each value from the JSON object
797797
ns::person p {
798-
j["name"].template get<std::string>(),
799-
j["address"].template get<std::string>(),
800-
j["age"].template get<int>()
798+
j["name"].get<std::string>(),
799+
    j["address"].get<std::string>(),
800+
    j["age"].get<int>()
801801
};
802802
```
803803
@@ -814,7 +814,7 @@ std::cout << j << std::endl;
814814
// {"address":"744 Evergreen Terrace","age":60,"name":"Ned Flanders"}
815815
816816
// conversion: json -> person
817-
auto p2 = j.template get<ns::person>();
817+
auto p2 = j.get<ns::person>();
818818
819819
// that's it
820820
assert(p == p2);
@@ -927,7 +927,7 @@ namespace nlohmann {
927927
if (j.is_null()) {
928928
opt = boost::none;
929929
} else {
930-
opt = j.template get<T>(); // same as above, but with
930+
opt = j.get<T>(); // same as above, but with
931931
// adl_serializer<T>::from_json
932932
}
933933
}
@@ -955,7 +955,7 @@ namespace nlohmann {
955955
// note: the return type is no longer 'void', and the method only takes
956956
// one argument
957957
static move_only_type from_json(const json& j) {
958-
return {j.template get<int>()};
958+
return {j.get<int>()};
959959
}
960960

961961
// Here's the catch! You must provide a to_json method! Otherwise, you
@@ -1059,11 +1059,11 @@ assert(j == "stopped");
10591059
10601060
// json string to enum
10611061
json j3 = "running";
1062-
assert(j3.template get<TaskState>() == TS_RUNNING);
1062+
assert(j3.get<TaskState>() == TS_RUNNING);
10631063
10641064
// undefined json value to enum (where the first map entry above is the default)
10651065
json jPi = 3.14;
1066-
assert(jPi.template get<TaskState>() == TS_INVALID);
1066+
assert(jPi.get<TaskState>() == TS_INVALID);
10671067
```
10681068

10691069
Just as in [Arbitrary Type Conversions](#arbitrary-types-conversions) above,

docs/mkdocs/docs/api/macros/json_disable_enum_serialization.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ The default value is `0`.
5353
const json j = Choice::first;
5454

5555
// normally invokes from_json parse function but with JSON_DISABLE_ENUM_SERIALIZATION defined, it does not
56-
Choice ch = j.template get<Choice>();
56+
Choice ch = j.get<Choice>();
5757
}
5858
```
5959

@@ -86,7 +86,7 @@ The default value is `0`.
8686
const json j = Choice::first;
8787

8888
// uses user-defined from_json function defined by macro
89-
Choice ch = j.template get<Choice>();
89+
Choice ch = j.get<Choice>();
9090
}
9191
```
9292

@@ -109,7 +109,7 @@ The default value is `0`.
109109

110110
void from_json(const json& j, Choice& ch)
111111
{
112-
auto value = j.template get<std::string>();
112+
auto value = j.get<std::string>();
113113
if (value == "first")
114114
{
115115
ch = Choice::first;
@@ -122,7 +122,7 @@ The default value is `0`.
122122

123123
void to_json(json& j, const Choice& ch)
124124
{
125-
auto value = j.template get<std::string>();
125+
auto value = j.get<std::string>();
126126
if (value == "first")
127127
{
128128
ch = Choice::first;
@@ -139,7 +139,7 @@ The default value is `0`.
139139
const json j = Choice::first;
140140

141141
// uses user-defined from_json function
142-
Choice ch = j.template get<Choice>();
142+
auto value = j.get<std::string>();
143143
}
144144
```
145145

docs/mkdocs/docs/api/macros/json_use_implicit_conversions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ By default, implicit conversions are enabled.
4646

4747
```cpp
4848
json j = "Hello, world!";
49-
auto s = j.template get<std::string>();
49+
auto s = j.get<std::string>();
5050
```
5151

5252
## See also

docs/mkdocs/docs/examples/from_json__default_constructible.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ int main()
3131
j["address"] = "744 Evergreen Terrace";
3232
j["age"] = 60;
3333

34-
auto p = j.template get<ns::person>();
34+
auto p = j.get<ns::person>();
3535

3636
std::cout << p.name << " (" << p.age << ") lives in " << p.address << std::endl;
3737
}

docs/mkdocs/docs/examples/from_json__non_default_constructible.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ int main()
4747
j["address"] = "744 Evergreen Terrace";
4848
j["age"] = 60;
4949

50-
auto p = j.template get<ns::person>();
50+
auto p = j.get<ns::person>();
5151

5252
std::cout << p.name << " (" << p.age << ") lives in " << p.address << std::endl;
5353
}

docs/mkdocs/docs/examples/get__PointerType.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ int main()
99
json value = 17;
1010

1111
// explicitly getting pointers
12-
auto p1 = value.template get<const json::number_integer_t*>();
13-
auto p2 = value.template get<json::number_integer_t*>();
14-
auto p3 = value.template get<json::number_integer_t* const>();
15-
auto p4 = value.template get<const json::number_integer_t* const>();
16-
auto p5 = value.template get<json::number_float_t*>();
12+
auto p1 = value.get<const json::number_integer_t*>();
13+
auto p2 = value.get<json::number_integer_t*>();
14+
auto p3 = value.get<json::number_integer_t* const>();
15+
auto p4 = value.get<const json::number_integer_t* const>();
16+
auto p5 = value.get<json::number_float_t*>();
1717

1818
// print the pointees
1919
std::cout << *p1 << ' ' << *p2 << ' ' << *p3 << ' ' << *p4 << '\n';

docs/mkdocs/docs/examples/get__ValueType_const.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ int main()
2222
};
2323

2424
// use explicit conversions
25-
auto v1 = json_types["boolean"].template get<bool>();
26-
auto v2 = json_types["number"]["integer"].template get<int>();
27-
auto v3 = json_types["number"]["integer"].template get<short>();
28-
auto v4 = json_types["number"]["floating-point"].template get<float>();
29-
auto v5 = json_types["number"]["floating-point"].template get<int>();
30-
auto v6 = json_types["string"].template get<std::string>();
31-
auto v7 = json_types["array"].template get<std::vector<short>>();
32-
auto v8 = json_types.template get<std::unordered_map<std::string, json>>();
25+
auto v1 = json_types["boolean"].get<bool>();
26+
auto v2 = json_types["number"]["integer"].get<int>();
27+
auto v3 = json_types["number"]["integer"].get<short>();
28+
auto v4 = json_types["number"]["floating-point"].get<float>();
29+
auto v5 = json_types["number"]["floating-point"].get<int>();
30+
auto v6 = json_types["string"].get<std::string>();
31+
auto v7 = json_types["array"].get<std::vector<short>>();
32+
auto v8 = json_types.get<std::unordered_map<std::string, json>>();
3333

3434
// print the conversion results
3535
std::cout << v1 << '\n';

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
@@ -48,10 +48,10 @@ int main()
4848

4949
// deserialization: json -> person
5050
json j2 = R"({"address": "742 Evergreen Terrace", "age": 40, "name": "Homer Simpson"})"_json;
51-
auto p2 = j2.template get<ns::person>();
51+
auto p2 = j2.get<ns::person>();
5252

5353
// incomplete deserialization:
5454
json j3 = R"({"address": "742 Evergreen Terrace", "name": "Maggie Simpson"})"_json;
55-
auto p3 = j3.template get<ns::person>();
55+
auto p3 = j3.get<ns::person>();
5656
std::cout << "roundtrip: " << json(p3) << std::endl;
5757
}

docs/mkdocs/docs/examples/nlohmann_define_type_intrusive_with_default_macro.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ int main()
3333

3434
// deserialization: json -> person
3535
json j2 = R"({"address": "742 Evergreen Terrace", "age": 40, "name": "Homer Simpson"})"_json;
36-
auto p2 = j2.template get<ns::person>();
36+
auto p2 = j2.get<ns::person>();
3737

3838
// incomplete deserialization:
3939
json j3 = R"({"address": "742 Evergreen Terrace", "name": "Maggie Simpson"})"_json;
40-
auto p3 = j3.template get<ns::person>();
40+
auto p3 = j3.get<ns::person>();
4141
std::cout << "roundtrip: " << json(p3) << std::endl;
4242
}

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
@@ -40,13 +40,13 @@ int main()
4040

4141
// deserialization: json -> person
4242
json j2 = R"({"address": "742 Evergreen Terrace", "age": 40, "name": "Homer Simpson"})"_json;
43-
auto p2 = j2.template get<ns::person>();
43+
auto p2 = j2.get<ns::person>();
4444

4545
// incomplete deserialization:
4646
json j3 = R"({"address": "742 Evergreen Terrace", "name": "Maggie Simpson"})"_json;
4747
try
4848
{
49-
auto p3 = j3.template get<ns::person>();
49+
auto p3 = j3.get<ns::person>();
5050
}
5151
catch (const json::exception& e)
5252
{

0 commit comments

Comments
 (0)