yaml-cpp/test/node
Pras Velagapudi ff9a466152 Add an into() operator on Node to do optional assignment.
This adds an `into()` operator to the Node class modeled off
the `get_to()` operator in the popular nlohmann::json library.
(See: https://github.com/nlohmann/json#basic-usage)

This operator assigns a casted value to an existing variable
if that node has a defined value, and otherwise leaves the
variable unchanged.  It returns `true` if the variable was
overwritten and `false` if the variable was unchanged.

This operator is extremely useful in applications where YAML
is being used as a configuration source that overrides
default values coming from another source, e.g.:

```c++
struct MyConfig {
  int foo = 4;
  double bar = 5.0;
  std::string baz = "six";
};

MyConfig config;
node["foo"].into(config.foo);
node["bar"].into(config.bar);

if (!node["baz"].into(config.baz))
  std::cerr << "Using default value for .baz!" << std::endl;
```
2021-11-25 09:30:53 -05:00
..
node_test.cpp Add an into() operator on Node to do optional assignment. 2021-11-25 09:30:53 -05:00