Numeric scalar conversions inside basic_node::get_value API #419
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds numeric scalar conversions, such as
float
toint
, inside thebasic_node::get_value
function.This change was suggested here by @ARessegetesStery to provide easier and more natural access methods to YAML node values in a similar way in which C++ handles primitives.
The conversions follows these rules:
false
(boolean)0
(integer)0.0
(floating point)1 /*true*/
or0 /*false*/
(integer)1.0 /*true*/
or0.0 /*false*/
(floating point)true /*non-0*/
orfalse /*0*/
(boolean)static_cast
ed floating point value (floating point)true /*non-0*/
orfalse /*0*/
(boolean)static_cast
ed integer value (integer)If all the above are not applied, the
basic_node::get_value
function throws atype_error
exception, which is unchanged.Pull Request Checklist
Read the CONTRIBUTING.md file for detailed information.
Please don't
#ifdef
s or other means.