Skip to content
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

parse float as integer #117

Open
X1aomu opened this issue Jan 15, 2020 · 0 comments
Open

parse float as integer #117

X1aomu opened this issue Jan 15, 2020 · 0 comments

Comments

@X1aomu
Copy link

X1aomu commented Jan 15, 2020

Given the follow toml:

[default]
size = 9.0 # This should be integer, but it was given a float accidently

And the parsing code:

constexpr size_t kDefaultSize = 3;
auto defaultSize = _config->get_qualified_as<size_t>("default.size").value_or(kDefaultSize);
cout << defautSize << endl;

Here we get the output:

3

Currently, it just act like that the key defaut.size is never present in the toml file, and then it finally get the default value. But, it does present, which confusing me a lot.

I know there exists a type mismatch. However, I think, in this case, it should either throw an exception to report that conversion couldn't be made or just cut the dicimal part out (9.0 -> 9 in this example).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant