You can get an iterator from a vector's index by adding the index to the iterator returned by begin(). That said, have you considered using std::remove() or std::remove_if() with the version of erase() that takes iterators that denote a range? That approach is less error prone and likely to be faster.
C + C++ Compiler: MinGW port of GCC
Build + Version Control System: SCons + Bazaar
Iterators could be more flexible than an index as erase returns an iterator to the element after the last element erased.
"It doesn't matter how beautiful your theory is, it doesn't matter how smart you are. If it doesn't agree with experiment, it's wrong."
Richard P. Feynman
I would have done find() but the list is of sockaddr_in's and all I have is an ip address and a port. so I have to go through each sockaddr_in and compare those internal values.
I would have done find() but the list is of sockaddr_in's and all I have is an ip address and a port. so I have to go through each sockaddr_in and compare those internal values.
That is where std::find_if() would come in handy.
C + C++ Compiler: MinGW port of GCC
Build + Version Control System: SCons + Bazaar
I second that! Just write a predicate functor and use find_if.
"It doesn't matter how beautiful your theory is, it doesn't matter how smart you are. If it doesn't agree with experiment, it's wrong."
Richard P. Feynman
Bookmarks