cpptoml icon indicating copy to clipboard operation
cpptoml copied to clipboard

parse float as integer

Open X1aomu opened this issue 5 years ago • 0 comments

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).

X1aomu avatar Jan 15 '20 08:01 X1aomu