yaml-cpp 在保存时如何重新排序节点?

How does yaml-cpp reorder the nodes when saving?

重写 .yaml 文件时,节点会重新排序。我似乎无法弄清楚它如何重新排序它们以及模式是什么。有谁知道重新排序是如何完成的?

这里是重写 .yaml 文件的代码:

YAML::Node config = YAML::LoadFile("config.yaml");
config["lastLogin"] = getCurrentDateTime();
std::ofstream fout("config.yaml");
fout << config;

如果我们查看 Node 的实现,我们发现它将其子节点存储在 std::map<Node*, Node*> 中,即从键节点指针到值节点指针的映射。

因此,节点按它们的指针值排序(这几乎是任意的,很可能从 运行 运行 改变),并且它们也是按该顺序写入的。