c++ - 对 YAML::Node 使用结构绑定
问题描述
当我们想要遍历 YAML::Node 时可以使用结构绑定吗?
当前代码:
for(auto it = node.begin(); it != node.end(); ++it)
{
auto a = it->first.as<std::string>();
auto b = it->second;
// Some code bellow
}
基于范围的 for 循环也可以正常工作:
for(const auto& n : node) {
auto a = n.first.as<std::string>();
auto b = n.second;
// Some code bellow
}
我希望得到类似的东西:
for(auto [a,b] : node)
{
// Some code bellow
}
这可能吗?如何将结构绑定与 YAML::Node 结合使用?更改的原因是代码更具可读性。这种类型的代码在多个地方使用,结构绑定是实现更漂亮的解决方案的好方法。
解决方案
推荐阅读
- sql - Oracle Select 语句中的工资差异
- python - 关于 Flutter 和 Python 之间的本地连接
- c# - 如何在 ASP Core 的静态类中使用“IWebHostEnvironment”
- ada - 为什么 GNAT 会拒绝具有默认判别值的数组类型?
- javascript - 在构建电子时如何提供自己的版本
- mysql - 是否可以使用 . 在名称中使用 ansible 模块?如何?
- c++ - 为什么`std::conj(double d)`不返回`double`而是`std::complex
`? - python - TypeError:“linehistory”对象不是迭代器
- node.js - 可以通过浏览器控制台访问firebase来创建用户吗?
- python - 如何从 AWS 胶水中的 Odata url 读取数据并写入 AWS 中的 S3 存储桶