-
-
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
Add templated version of DEFINE_TYPE macros #2843
base: develop
Are you sure you want to change the base?
Conversation
In the macros added, it's impossible to follow // sample code
#define start_class(A, type) class A { type:
// these wouldn't compile
#define start_class2(A, type) class (A) { type:
#define start_class3(A, type) class A { (type): |
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.
Flex check and fix the issue found in the CI:
Hopefully fixed the first. Regarding the second error, please find my analysis in the comment above yours (#2843 (comment)) |
There is some issue with the CI - the job |
Can you please update to the latest develop branch? The CI issues should be fixed then. Sorry for the inconvenience. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
@kunaltyagi Can you update to the latest develop branch? |
Rebased, and also refactored the code to make the macros a bit less offensive |
Almost all tests are passing. Current issue:
If someone can identify the source, I can make a workaround. |
It seems safe to just add a suppression for 4503. Edit: I'm leaning towards disabling it globally in
|
All checks pass. PTAL |
Are there any more blockers? 😅 |
nlohmann::json j1 = obj1; //via msgpack | ||
std::vector<uint8_t> buf = nlohmann::json::to_msgpack(j1); | ||
nlohmann::json j2 = nlohmann::json::from_msgpack(buf); | ||
json_t j1 = obj1; //via msgpack |
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 don't know how much sense it makes to test the different formats here. To the extent that there are roundtrip differences, these are best tested elsewhere.
You're also missing BJData, and when the BON8 PR is merged, this is likely to be missed.
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.
This is existing code, which I modified (parameterized on different types) to support different underlying implementations for json: ordered and unordered map
I'd prefer to tackle the missing BJData and BON8 in a separate PR. Thoughts?
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.
This is existing code, which I modified
Right. You don't need to do anything else here as far as I'm concerned.
@nlohmann @gregmarr Am I missing something? There are differences in formats (e.g., NaN
serializing as null
) that will cause problems when using these macros (which also might be worth mentioning in the documentation until fixed) but that's not what's being tested here. So what's the point?
Should we remove these tests (later, in a separate PR)?
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.
Here's the PR where they were added: #2287
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 just find the choice of roundtripping bizarre. It's already tested extensively for each format and unless you're testing the corner cases (which the macros don't handle anyway), there's no reason to do so here. Let's just do something to pad the unit test! 🤷♂️
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 referenced PR was created due to a bug where if you had 10 elements in the object, it would skip processing element 9 or just fail to compile due to an error in some hand-written code, so I think this is testing that it is including all of the named elements. #2267
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.
Still, why test different formats? Ignoring format-specific exceptions, a roundtrip doesn't change the basic_json
.
SECTION("alphabet")
{
json_t j = obj1;
T obj2;
j.get_to(obj2);
CHECK((obj1 == obj2));
}
Is this not sufficient?
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.
Could be, don't know for sure. @pfeatherstone did you have a particular reason for not just doing one format here?
@kunaltyagi It would be great to have this feature in the library. Do you have time to work on the remaining issues or should someone take over? |
I think the sole unaddressed comment explicitly states that I don't need to take any action. What issues are remaining? |
Oh I'm sorry - this was meant for @pfeatherstone... |
Seems to be not available. Btw, can we change the label on the PR? |
Is there a reason we can't make Instead, I think we should (in a separate PR, of course) explore refactoring and renaming some of the implementation macros (i.e., |
This PR was a pain to rebase to master. Is it possible to move it ahead? |
Those are templated versions. They would behave a bit differently with overloading than the current versions. The existing code in the repo wouldn't be broken, but the user experience might be affected due to how templates participate in overload resolution (wrt implicit conversions), which is surprising when compared to non-overloaded versions |
Non-template functions are preferred over template functions during overload resolution – true. I did not consider that. Still, what are the practical, real-world implications in this particular context? When I have some time later, I'll try to construct a contrived example to trigger different behavior, but If I even manage to do so, I wouldn't expect to find this in the wild. Maybe GitHub Code Search can help. A separate issue came to mind: |
The open issues are:
These shouldn't be too difficult to resolve and I'm holding back work on substantial changes until after this PR is merged. |
Sure. I'll check if that's needed. If it is, I'll add that to the PR.
Someone will have to get that merged in master outside the PR. I don't disagree on your stand, just that it's not nice to bundle it in this PR.
cc: @nlohmann |
Right, I forgot that that's not something you added. |
I agree fully with @falbrechtskirchinger. |
@kunaltyagi Heads up. To satisfy the new |
Some months have passed whats the status on this? ;) |
How many programmers need to support templated BasicJsonType in NLOHMANN_DEFINE_TYPE_MEOW? This macro is cursed |
Picking up from #2532
make amalgamate
was not found, so the change was performed manuallyPull 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.