-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
Issues around get and pointers #1653
Comments
I checked with version 3.6.1 as well, same issue. Leaving aside for the moment the question of how you want pointer type; must be a pointer to array_t, object_t, string_t, boolean_t, number_integer_t, number_unsigned_t, or number_float_t. Since this is a requirement that's already documented, it's not a breaking change to actually sfinae on this. Right now we have:
If we change |
Indeed there seems to be too much magic in And you're right - adding a better type restriction should not only solve the issue, but would also not be a breaking change, as I'd be happy if you had a PR for this, but I can also fix this myself. |
No worries, thanks for your response. Sure, happy to push a patch, hopefully tomorrow. How long do you think until you'll want to do a release (minor/patch) that incorporates this? |
I'm planning to make the next release (this 3.7.0) some time in July. |
I'm genuinely confused. Tried to add a unit test that shows the failure first, and i wasn't able to produce it. I tried adding the following to unit-udt.cpp:
And everything compiles fine. I'm not quite sure what I'm missing... Will have to look at it again. |
Based on my error message and looking at the upstream source, maybe this has already been solved, because the get function went from a regular return type to a trailing return type which might give further sfinae opportunities... I'll look at this again tomorrow. |
Did you have the chance to have a look at this? |
I think I was mistaken and this was fixed (indirectly) in later versions. From version 3.6.1, there is return type sfinae in these get functions which seems to solve the issue. The confusion was caused by my package manager using 3.1.0 even though I had selected 3.6.1 :-(. So I don't think any action is needed for now. In a 4.0 release though, I'd still suggest that |
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. |
The internal type of numbers is |
I use nlohmann json quite extensively to de-serialize many types from json conveniently. I've written from_json specializations for quite a few standard library types and third party types, and recently I've come across a very awkward situation.
I'm currently working with the Howard Hinnant date library, which is also slated for inclusion in C++20 IIRC. One of the aspects of this library is that it's not really possible to work directly with timezone objects. The timezone objects themselves are stored in a singleton that is typically constructed at initialization time from reading the OS IANA database. Instead, you call
const date::timezone* date::locate_zone(string_view)
; that is in user code you mostly work with pointers to const timezones instead.So, I write code like this:
However, the problem is that when I call
j.get<const date::time_zone*>
, I get a compiler error for ambiguity, with candidates:One rather ugly workaround is to write my own type,
TimeZone
, that internally holds such a pointer. I consider this ugly because I would just have to do conversions back and forth to actually work with date code and it's just introducing a new type for no reason.I was wondering if there is a better workaround that I could use, or if I'm misusing something?
Based on what I've seen, I think it is wrong that
get
has specializations that behave differently for pointer types; it seems like a convenience (kinda) that breaks generic code; this behavior should be saved forget_ptr
. But perhaps I've misunderstood the situation.The text was updated successfully, but these errors were encountered: