-
-
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
user-defined types ter: clean, refactor basic_json class #423
user-defined types ter: clean, refactor basic_json class #423
Conversation
{ | ||
return get_impl(static_cast<ValueType*>(nullptr)); | ||
-> decltype(this->get_impl(static_cast<ValueType *>(nullptr))) { | ||
return get_impl(static_cast<ValueType *>(nullptr)); |
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.
The brace here doesn't match the style of the rest of the library.
{ | ||
if (!j.is_boolean()) | ||
throw std::domain_error("type must be boolean, but is " + type_name(j)); | ||
b = *const_cast<Json&>(j).template get_ptr<typename Json::boolean_t*>(); |
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.
Is there no way to do this without a const_cast?
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.
I think it can, adding const to the get_ptr
template arg should be good
{ | ||
if (!j.is_string()) | ||
throw std::domain_error("type must be string, but is " + type_name(j)); | ||
s = *const_cast<Json&>(j).template get_ptr<typename Json::string_t*>(); |
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.
As in boolean version, can this be done without const_cast?
friend bool operator==(json_pointer const &lhs, | ||
json_pointer const &rhs) noexcept | ||
{ | ||
return lhs.reference_tokens == rhs.reference_tokens; |
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 like this library uses 4 space indents.
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.
I added run make pretty
to the list of things to be done
/// the reference tokens | ||
std::vector<std::string> reference_tokens {}; | ||
}; | ||
}; |
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.
Something still seems off about this brace indentation.
bed76d7
to
2f85d37
Compare
8cc2423
to
7a7bc07
Compare
b023103
to
3affbfa
Compare
I think the If someone finds an edge-case, or something I missed, please let me know |
@nlohmann Hi Niels, do you think we could meet on Slack soon? I'd like to have your input on some things See you soon! |
I added a bit of doc, but frankly I'm terrible at this, so I'd gladly take some help on this part! But once the doc and examples are done, I think we can merge it. EDIT: Right now we have this json j;
auto v = json.get<std::vector<int>&>();
// decltype(v) == std::vector<int>
auto u = json.get<const std::vector<int>>();
//decltype(u) == decltype(v) I I think it doesn't make any sense, so I tried to remove that and add some However, it broke the existing tests, in So, should we keep this behavior for those types, and |
1cb3b59
to
3843fa3
Compare
ec671b5
to
8d2216f
Compare
Unless I missed something, it is ready to be merged (minus documentation). |
This can however not be done easily for value_t, since external_constructor depends on it, as is operator< which was moved outside basic_json too. This is not really an issue, since all basic_json classes share the same enum
8d2216f
to
9c6ef74
Compare
@nlohmann Code-wise, I'm done! Ready to merge :) |
Very nice! I see whether I can do the merge tomorrow. |
Changes moved to #435 which will be merged once the tests complete. Thanks everybody for the hard work over the last months! |
Hi!
This PR is the follow-up of #355
I managed to replace a lot of constructors with
from/to_json
overloads, which helped me to remove some SFINAE boilerplate, and to add a new feature: giving full control on type serialization to whom needs it.I advise reviewers to review commit per commit, I tried my best to separate everything.
Things that need to be done