Use structure binding for YAML::Node

Viewed 125

It is possible to use structure binding when we want to iterate through YAML::Node?

Current code:

for(auto it = node.begin(); it != node.end(); ++it)
{
  auto a = it->first.as<std::string>();
  auto b = it->second;
  // Some code bellow
}

Range-based for loop also works fine:

for(const auto& n : node) {
  auto a = n.first.as<std::string>();
  auto b = n.second;
  // Some code bellow
}

I wish to get something like that:

for(auto [a,b] : node)
{
  // Some code bellow
}

Is that possible and how can I use structure binding with YAML::Node? The reason for the change is more readable code. This type of code is used in multiple places and structure binding is a good way to implement a prettier solution.

0 Answers
Related