-
-
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
initializer list constructor makes curly brace initialization fragile #1594
Comments
The problem is known, and changing it would be a breaking change... |
As for operator T(), right? I would say it should be part of the same discussion. Or a version 2 started, which has less magic and better composbility? |
Would probably be a good idea to mention this in the documentation. The Cpp Core Guidelines recommend always using value initialization, so I expect a lot of people are doing that. Had this problem today, and it took me a good while to locate it, and didn't fully understand it before finding this issue. |
@olavurmortensen It is mentioned in the FAQ. Where did you look? In other words, where should it be mentioned to make it more discoverable? Probably at least the constructor, where I can't find it. |
I've only read in the reference: |
Hey,
I just discovered when i convert something to json on the fly like this:
nlohmann::json{my_value}
it turns it into an array, which is highly unexpected. this is a bit like the operator T() problem: too muc magic. I would be less dangerous if array/object construction where explicit, i.e. json::array({....})/json::object({{key, value},...). one can even make json::array/object objects and lose the round braces.
The text was updated successfully, but these errors were encountered: