Can we rely on value_unsafe() returning "default" values of the underlying type? #2280
Unanswered
VishalSubramanyam
asked this question in
Q&A
Replies: 1 comment
-
Right now, we don't even test for this behaviour, so we can't very well guarantee it. However, if you'd be willing to contribute good tests, we could change this policy. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Yes, I know it's called "unsafe". Yes, I know that the official "contract" is that I should not rely on it. But realistically, can I rely on the following behavior?
I don't want to constantly be checking if a certain field is present or if its field value is not parsable for the expected type. For example,
would lead to value.error() being true if the JSON is something like
But I don't mind value.value_unsafe() returning 0 or whatever the default value is. For example,
if value.value_unsafe() gives me an empty string_view, that's fine by me.
Right now, I ran some tests, and it looks like simdjson does the above, like I want it to, and skimming through the code, it looks like the values are default-constructed. Can I rely on this?
Beta Was this translation helpful? Give feedback.
All reactions