Skip to content

Failing to traverse when erasing a node using a breadth_first_queued_iterator #27

@t114211200

Description

@t114211200
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.
	}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions