-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
forced type conversion or lexical cast without exception. #1955
Comments
Is there a specific reason why you'd want this as a member funciton instead of just a free-floating utility function? It's not like anything is preventing you from creating a wrapper around your boilerplate:
|
I agree with @FrancoisChabot - the use case is too special to justify adding it to the public API to the library. |
@FrancoisChabot This is what I am currently doing. This It can be a free function instead of being a member function. But I'd prefer this to be part of the json library. Not only about integral type I am talking about generalizing |
I think a util header is the best choice. The public API should only contain functions that are widely used. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
json["index"].force<int>(-1)
that will first check whether the current type ofjson["index"]
is directly cast-able toint
. If cast-able then do astatic_cast
. Otherwise convert the internal value to string (all json values can be converted to string representation). Then uselexical_cast<int>
on that value. If both of these fails then return the default value0
provided.currently this is what I am doing.
I would prefer this to be done like
The text was updated successfully, but these errors were encountered: