Search code examples
c++xmliteratorboost-propertytree

How to iterate a boost property tree?


I am know approaching to boost property tree and saw that it is a good feature of boost libs for c++ programming.

Well, I have one doubt? how to iterate a property tree using iterators or similar?

In reference there is just an example of browsing the tree through:

BOOST_FOREACH

But is there nothing more? Something like an stl-like container? It would be a better solution, speaking about code quality....


Solution

  • BOOST_FOREACH is just a convenient way for iterating that can be done by iterator, begin() and end()

    Your_tree_type::const_iterator end = tree.end();
    for (your_tree_type::const_iterator it = tree.begin(); it != end; ++it)
        ...
    

    And since C++11 it's:

    for (auto& it: tree)
        ...