boost::property_tree::xml_parser::read_xml 是否保留顺序?

Does boost::property_tree::xml_parser::read_xml preserve the order?

考虑以下 xml 元素:

<elem>
    <sub_elem name="first">
    <sub_elem name="second">
</elem>

关于boost::property_tree::xml_parser::read_xml填充的属性树,是否保证sub_elem"first"会在sub_elem"second"之前?

documentation 状态:

Reads XML from an input stream and translates it to property tree.

然而,这取决于 "translates" 的确切含义。

来自 属性 树文档:https://www.boost.org/doc/libs/1_65_1/doc/html/property_tree/container.html 我推断 XML 文件中的元素顺序被保留

It is very important to remember that the property sequence is not ordered by the key. It preserves the order of insertion. It closely resembles a std::list. Fast access to children by name is provided via a separate lookup structure. Do not attempt to use algorithms that expect an ordered sequence (like binary_search) on a node's children.

查看 https://www.boost.org/doc/libs/1_51_0/boost/property_tree/detail/xml_parser_read_rapidxml.hpp 中的内部代码,您可能会看到遍历节点和 push_back 调用。它确实应该以保持顺序的最简单方式工作。