tree<int> tr;
auto top = tr.begin();
auto root = tr.insert(top, 0);
auto a1 = tr.append_child(root, 1);
auto a2 = tr.append_child(root, 2);
auto a3 = tr.append_child(root, 3);
tr.append_child(a1, 11);
tr.append_child(a1, 12);
tr.append_child(a1, 13);
tr.append_child(a2, 21);
tr.append_child(a2, 22);
tr.append_child(a2, 23);
tr.append_child(a3, 31);
tr.append_child(a3, 32);
tr.append_child(a3, 33);
auto iter = tr.begin_breadth_first();
auto end = tr.end_breadth_first();
while (end != iter)
{
if (*iter == 2) // erase '2'
{
iter = tr.erase(iter);
}
else
{
cout << *iter << endl;
++iter; // The node '2' is still being traversed, but it has already been deleted.
}
}