yaml-cpp
yaml-cpp copied to clipboard
Tutorial: How to allow for optional fields?
The tutorial seems to require all fields to have values in the user's YAML file. However, many configurations permit omitting fields and falling back on defaults. Could we please expand the tutorial to show an example for this?
Update:
I now see the IsMap() is another option when validating and decoding YAML Nodes. Would be helpful to include an example using maps in the tutorial, and link to the API docs from the README.
You can pass a default value in the as operator, eg.
int x = node["x"].as<int>(42);
Will set x to 42 if the property is missing.