-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add note on derived return type for value function (#4628)
* 📝 add note on derived return type Signed-off-by: Niels Lohmann <mail@nlohmann.me> * 📝 add note on derived return type Signed-off-by: Niels Lohmann <mail@nlohmann.me> --------- Signed-off-by: Niels Lohmann <mail@nlohmann.me>
- Loading branch information
Showing
5 changed files
with
84 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#include <iostream> | ||
#include <nlohmann/json.hpp> | ||
|
||
using json = nlohmann::json; | ||
|
||
int main() | ||
{ | ||
json j = json::parse(R"({"uint64": 18446744073709551615})"); | ||
|
||
std::cout << "operator[]: " << j["uint64"] << '\n' | ||
<< "default value (int): " << j.value("uint64", 0) << '\n' | ||
<< "default value (uint64_t): " << j.value("uint64", std::uint64_t(0)) << '\n' | ||
<< "explict return value type: " << j.value<std::uint64_t>("uint64", 0) << '\n'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
operator[]: 18446744073709551615 | ||
default value (int): -1 | ||
default value (uint64_t): 18446744073709551615 | ||
explict return value type: 18446744073709551615 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters