-
Notifications
You must be signed in to change notification settings - Fork 166
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
Type conversion between numeric types #140
Comments
I basically agree with your point, it would be more useful if it can convert int64_t into float and vice versa. But there is a reason why it is not supported. When we specify a type that does not require any type conversion, it returns a reference (like int64_t& x = toml::find<int64_t>(input, "x");
x = 42; // overwrite "x" in `input` But, it is not possible to bind So the available options are
I think the most feasible option is the last one. |
Understood, I hadn't appreciated the reference problem. To forge ahead, I worked around it in my code with a simple Your proposed solution sounds perfect though, thank you for taking the time to read and think about my question! |
Could it give a warning if a key exists but with wrong type? |
In the README it mentions that conversion between int/floating cannot be done implicitly. Is this really not possible?
If a user wants to set a starting position vector as the origin, having
fail to be read by
toml::get<std::vector<double>>(start_table.at("position"))
is quite frustrating. I appreciate that doing implicit lossy conversions (1.2
as an int for example) might be an implementation choice, but the inability to get0
as a double seems to be a bit arbitrary. If it is technically possible but not something you feel the need to implement, then I might have a look.Thanks for the great library!
The text was updated successfully, but these errors were encountered: