IHateMyJob2004
Lifer
Having become somewhat of a Java guru, I have come to hate STL. Regardless I have to use it.
Now, regarding the STL vector, how do I go about iterating through the vector and removing items as I iterate?
In Java it is easy, all you do is call iter.remove(). Done. STL can not be so simpel though. So, what do I have to do to go through a vector and remove them (depending on criteria) as I go through them?
It's a small set so efficiency is a non issue.
Also, are there any other STL collections I should use? The 'list' is a linked list which would be more efficient at removing items mid-list. If I went this route, is it easier to go through the list and remove tiems on a case by case basis?
EDIT: If anyone could go through and write some code for me, that would be awesome. Something like this:
OK.... why is that code not formatted properly? SHould have looked like this:
list::iterator iter = someList.iterator();
for (;iter != someList.end(); iter++) {
Foo foo = *(iter);
if (foo.getX() == 5) {
// TODO: remove foo
}
}
Now, regarding the STL vector, how do I go about iterating through the vector and removing items as I iterate?
In Java it is easy, all you do is call iter.remove(). Done. STL can not be so simpel though. So, what do I have to do to go through a vector and remove them (depending on criteria) as I go through them?
It's a small set so efficiency is a non issue.
Also, are there any other STL collections I should use? The 'list' is a linked list which would be more efficient at removing items mid-list. If I went this route, is it easier to go through the list and remove tiems on a case by case basis?
EDIT: If anyone could go through and write some code for me, that would be awesome. Something like this:
OK.... why is that code not formatted properly? SHould have looked like this:
list::iterator iter = someList.iterator();
for (;iter != someList.end(); iter++) {
Foo foo = *(iter);
if (foo.getX() == 5) {
// TODO: remove foo
}
}