Jump to content
  • Advertisement
Sign in to follow this  
gumpy

stl iterator question

This topic is 4828 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i read somewhere that container.erase( iterator ) returns the next element. i may have misunderstood, but is this possible?
	std::list<Client>::iterator i = m_client.begin( );
	while( i != m_client.end( ) )
	{
		if( FD_ISSET( i->fd, &exception_fds ) )
			i = m_client.erase( i );
		else
			++i;
	}


Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by gumpy macdrunken
i read somewhere that container.erase( iterator ) returns the next element. i may have misunderstood, but is this possible?
*** Source Snippet Removed ***


Nope that is correct, if you just want to conditionally remove all occurrences of some given criteria/value you can use std::list's remove/remove_if method or the generic algorithm remove/remove_if (then use range version of std::list::erase for this one) instead of explicit hand loop code.

The "_if" versions takes custom unary predicate type (any C++ unary callable entity, free/member function, functor etc) while the non "_if" versions assume equality operator supported for the type in question.

Although not 100% accurate this has to be one of the best online references on the standard library containers & algorithms.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!