std::optional not working with primitive types #2383
Labels
kind: bug
state: stale
the issue has not been updated in a while and will be closed automatically soon unless it is updated
What is the issue you have?
I'm currently trying to implement the to_json conversion function for the std::optional type. Here is the function
But when using it with T as a primitive type, I get an compiler (and linter) error which says :
But with non-primitive type, everything work as expected, as long as I define the appropriate to_json function for that non-primitive type.
Please describe the steps to reproduce the issue.
Here's a code for testing :
Uncomment the commented line and this code will no compile anymore, even if I declare a function like :
...it doesn't change anything.
What is the expected behavior?
It should convert the std::optional into json double as the to_json function for the std::optional convert either nullptr or T to json if it has a value and as double is primitively supported by NlohmannJson.
And what is the actual behavior instead?
It doesn't find any way to convert the std::optional value into json value.
Which compiler and operating system are you using?
Which version of the library did you use?
develop
branchThe text was updated successfully, but these errors were encountered: