Boost & Spirit : How to reverse iterate a tree?

Started by
1 comment, last by nukomod 18 years, 9 months ago
I've got an abstract symbol tree to reverse parse but as far as I can see there isn't a reverse iterator for it. It's going to sit in a big recursive function that passes an iterator for the children of each node on to itself. Here's the forward iterator version: ProcessNode(boost::spirit::tree_match<char const*>::const_tree_iterator nodeIter) { boost::spirit::tree_match<char const*>::const_tree_iterator iter_t; for(iter_t = nodeIter->children.begin(); iter_t != nodeIter->children.end(); iter_t++) { ProcessNode(iter_t); } } Now if I want to go backwards what do I use?
Advertisement
so far I have this, but I don't trust it and haven't tested fully if it works yet, but I doubt it does work right.

if(nodeIter->children.size() > 0)
{
boost::spirit::tree_match<char const*>::const_tree_iterator iter_t;
for(iter_t = nodeIter->children.begin()+(nodeIter->children.size()-1);
iter_t != nodeIter->children.begin(); iter_t--)
{
ProcessNode(iter_t);
}
}
And now... which seems to be working ok.. but still suspicious I am...

iter_t = nodeIter->children.begin()+(nodeIter->children.size());
do
{
iter_t--;
ProcessNode(iter_t);


} while(iter_t != nodeIter->children.begin());

This topic is closed to new replies.

Advertisement