-
-
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
NLOHMANN_JSON_FROM* macros not comptaible with non-default-constructible types #4247
Comments
This is documented behavior, see https://json.nlohmann.me/api/macros/nlohmann_define_type_non_intrusive/#parameters |
In this case, I need to use the Would you be open to tracking this deficiency as a feature request/request for enhancement then? |
Sure - though I hope it does not mean adding another dozen of macros for this case... |
That's simply because you didn't implement the version of
@nlohmann It would probably be a good idea to update the docs examples to use the |
Just curious, why the forwarding reference? When I try it, it seems to work with a |
It should probably just be |
Description
The family of
NLOHMANN_JSON_FROM*
macros all seem to be incompatible with any kind of type that does/cannot have a default constructor.Reproduction steps
See code example below, including Godbolt link.
Expected vs. actual results
Expected result: There is a macro available that can generate a
from_json
function that compiles successfully.Actual result: Template compile error.
Minimal code example
Given the following simple class:
From the documentation I gather that the only way to json-convert this type is to specialize
adl_serializer
for it:This works just fine, but now structs containing this type cannot be json-converted using the macros anymore:
Godbolt link: https://godbolt.org/z/q8oxq61sx (gcc trunk, nlohmann_json trunk)
Error messages
Compiler and operating system
g++ 11.4, g++ trunk, clang++ 11.0.1, clang trunk, OS: ubuntu 22.04/godbolt
Library version
3.11.3
Validation
develop
branch is used.The text was updated successfully, but these errors were encountered: