Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example to fixed_depth_iterator / missing end-iterator for fixed_depth_iterator #5

Open
etiwal opened this issue Oct 28, 2020 · 3 comments
Labels
enhancement New feature or request how to (question) Further information is requested

Comments

@etiwal
Copy link

etiwal commented Oct 28, 2020

When i try to use the fixed_depth iteration i am running into issues.

First of all this assertion always blocks my code from running:
assert(1==0); // FIXME: not correct yet: use is_valid() as a temporary workaround

Also i have issues when using the begin_fixed() and end_fixed() to define the range of my iteration.

could you maybe provide an example on how to properly iterate over all the nodes at a certain depth and within this iteration create a child for every node?

Any help is greatly appreciated!

@kpeeters
Copy link
Owner

kpeeters commented Nov 7, 2020

The fixed-depth iterators lack proper STL behaviour in the sense that there is no end-iterator. But you can still iterate over elements at a fixed depth by getting the begin-iterator using auto it = begin_fixed(...) and then iterating until it.is_valid() no longer returns true. So something like

auto it = tr.begin_fixed(tr.begin(), 3);
while(it.is_valid()) {
    tr.append_child(it, ...);
    ++it;
}

Hope this helps; if not, ask again.

@jmccabe
Copy link

jmccabe commented Oct 9, 2023

auto it = tr.begin_fixed(tr.begin(), 3);
while(it.is_valid()) {
    tr.append_child(it, ...);
    ++it;
}

Sorry to revive an old question, but (unless I'm missing something) it looks like a fixed_depth_iterator doesn't have a is_valid() method; should this be using something like:

auto it = tr.begin_fixed(tr.begin(), 3);
while (tr.is_valid(it)) {
    tr.append_child(it, ...);
    ++it;
}

@kpeeters
Copy link
Owner

kpeeters commented Oct 9, 2023

@jmccabe Yes, sorry.

@kpeeters kpeeters added the enhancement New feature or request label Jul 19, 2024
@kpeeters kpeeters changed the title Example to fixed_depth_iterator Example to fixed_depth_iterator / missing end-iterator for fixed_depth_iterator Jul 19, 2024
@kpeeters kpeeters added the how to (question) Further information is requested label Jul 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request how to (question) Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants