-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix issue#1275 #2181
Fix issue#1275 #2181
Conversation
Reading through #1275, my impression is that the consensus was that moving out the value from the json object was deemed too surprising for users. That aside, So in my mind, this PR should either:
|
@FrancoisChabot thank your advices! I think the first point is better, cause the second one will wait until the next major release, that will be a very long time. And the third one, I think it isn't the thing about the range of the default value. |
Pedantically, I think this PR should ideally be 3), since that's what #1275 is about. 1) is practically a new feature in of itself. But honestly, I'm personally not a huge fan of 1). I do not like extra API surface for the sake of minor QoL features in general. I can do |
I'm against breaking the API, and I am not really convinced that adding a new function is really helpful. This is a very small corner case, and it is possible to implement it via the public API. |
Ok, I will not add a new function to break the API, but only focus on 3). |
It's just an awkward way of saying that the function would now accept R-Value references when appropriate. |
@nlohmann @FrancoisChabot Are you satisfied with the last changes? |
This looks fine to me. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
Thanks! |
This comment has been minimized.
This comment has been minimized.
just break my code
json.hpp:19714:25: warning: returning reference to temporary [-Wreturn-local-addr] |
@lethe555 Which line is 19714? Assuming it's the |
error: no matching function for call to 'nlohmann::basic_json<>::value(const char [2], std::string&)' now default_value seems can't be a lvalue , but use a lvalue as default value is very common case |
I can confirm that the code in #2181 (comment) does not compile with the latest develop version. Reason is this PR. I shall revert the changes and add a regression test. Then, we can decide how to properly address #1275. |
Done. |
I think you might be able to do this same basic PR but using |
I can't get it to run:
|
@nlohmann
If you think it works, I would push it to the official repo. |
That would be great. |
Fix issue #1275 : add an overload of function
value(key, default_value)
.Pull request checklist
Read the Contribution Guidelines for detailed information.
include/nlohmann
directory, runmake amalgamate
to create the single-header filesingle_include/nlohmann/json.hpp
. The whole process is described here.