Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Optional keys with yaml-cpp 0.5.1

Tags:

c++

yaml-cpp

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

Unfortunately, I can't call this 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 which works in the latest version?

like image 488
paco_uk Avatar asked Feb 24 '14 10:02

paco_uk


1 Answers

In the new API, you can just check:

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

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

if (YAML::Node parameter = node["parameter"]) {
  // process parameter
}
like image 187
Jesse Beder Avatar answered Nov 03 '22 01:11

Jesse Beder