Thread Previous • Date Previous • Date Next • Thread Next |
On 2019-08-30 15:49, Sylwester Kocjan wrote:
m_schfields->erase( std::remove_if( m_schfields->begin(), m_schfields->end(), [&]( const SCH_FIELD& f ) { return f.GetName() == spiceField; } ), m_schfields->end() );
My question is, why deletion is repeated: at first there is called remove_if(), and later erase(), which will delete all the fields behind the removed one. From my point of view it looks like remove_if() only should be enough.
remove_if() re-orders the container and returns the iterator that points to the first matching element. erase() removes all elements from this iterator through the end of the container.
See https://en.wikipedia.org/wiki/Erase%E2%80%93remove_idiom
Thread Previous • Date Previous • Date Next • Thread Next |