-
-
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
Ambiguity in parsing nested maps #840
Comments
Have you tried using The compile errors would not take into account the input string at all. I would, however, expect that program to fail at runtime, as your json is invalid (you need to replace |
I did try |
But you're calling |
hah, you're right, I should have just done |
I'm not sure that the library can do nested retrieval like that without some help in the form of a |
Sure, here is the error:
I mean, the maps should have their own from_json and I don't see why this case shouldn't be handled. |
Here is also the part of the error backtrace from nlohman:
|
This doesn't line up with the head of devel. Which branch and commit are you using? I'm guessing this is the line:
This means that it's trying to create the unordered map using its range constructors, none of which match up. This will likely require that you implement |
@gregmarr It's not really a solution to implement from_json, because it's a recursive problem. I could implemented for It seems to me like this is a defect in the library, in the sense that there's no reason why the library couldn't do this correctly. I'll try to dig a bit more when I have a chance. If we know which constructor we want there should be a way to resolve the ambiguity. |
It could be possible to make the library do that, but I'm not sure it can be considered a defect that it doesn't have the ability to extract a particular type without writing a Note that this is not an ambiguity in parsing, as the title says, but rather in extracting the data to your desired data type. Maybe it's time to take a step back. Why are you trying to extract the data into that data type? What are you going to do with that data after you copy all of it into those maps? Could that be better done just by working with the |
I think we disagree somewhat on the library's responsibilities. The library already does this to a degree: if you create a type Applying this logic to I don't want to work directly with the json because a) it's much more weakly typed than the nested map, and I want to verify the type precisely at the config parsing stage, and use the data at a later stage knowing that the types have at least been verified, and b) I don't want to introduce dependencies on the json library deep into my code. I want to restrict the usage to simply parsing out json into useful structures, and then process those structures. I don't really want to focus on this though, because you may disagree but I think these are legitimate reasons, and in any case obviously these decisions are being made in the context of a broad code base that I'm not going to get into. |
I'm late to this discussion. Do we have a small example that demonstrates the problem with the |
When I tried it I had the same issue with map. I can't do it easily now but I can try to pull to HEAD when I get home and duplicate it with map. I expect though that if you try the original example and simply replace unordered_map with map, you will see the issue. |
Thanks, that would be great. |
That makes sense, thanks. I imagine that if @theodelrieu or @nlohmann can find a way to make this work easily, that it will get added. |
FYI, this compiles just fine with the latest code on the |
@gregmarr Ah great stuff! At first maybe I thought it was the compiler but it doesn't seem like it. I will verify at home, in which case I will be sure to close this. Maybe at that point I can bisect a little and see where exactly this was fixed. |
@quicknir Any news on this? |
Sorry I dropped this, will verify tonight. |
Confirmed this works on HEAD, and pretty sure it didn't in 2.1.1. Just curious if there is a release coming soon? If not I'll probably just grab HEAD. Thanks for your help! |
This is considered ambiguous and a compile time error:
The error is a bit long but I can paste it here if desired. I don't see why this is ambiguous, seems like given the input and the types I specified there is only one possible output. Is this considered a bug? Either way, is there a workaround?
The text was updated successfully, but these errors were encountered: