Additional keys with yaml-cpp 0.5.1

A previous answer describes how to check if a key exists in yaml node using YAML::Node::FindValue("parameter").

Unfortunately, I cannot call it in the latest version (0.5.1):

 error: ‘class YAML::Node’ has no member named ‘FindValue’

Is this expected to work or is there an equivalent function that works in the latest version?

+3
source share
1 answer

In the new API, you can simply check:

if (node["parameter"]) {
  // ...
}

It may be convenient to define an object in a block if (...):

if (YAML::Node parameter = node["parameter"]) {
  // process parameter
}
+4
source

All Articles