3 ms·
The correct idiom is delete list head until list is empty. The iterator may become invalid if the collection it derived from changes. Iterator delete methods
by sunir 15y ago
The correct idiom is delete list head until list is empty.
The iterator may become invalid if the collection it derived from changes.
Iterator delete methods are crazy to begin with since iteration does not correlate with deletion. But anyway it is not clear where the iterator's cursor will point after you delete the current element. You could end up deleting every second element in the container.
- morsch 15y agoMy example wasn't clearing the list, it's a filter. And depending on what language and library you're talking about, it's very clear where the cursor will point to after a delete. There's nothing crazy about it with an even halfway sane collection framework.