Jump to content
  • Advertisement
Sign in to follow this  
nukomod

Boost & Spirit : How to reverse iterate a tree?

This topic is 4832 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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);
}
}

Share this post


Link to post
Share on other sites
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());

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!