Std::remove_if

Source: Internet
Author: User

Prototypes:
#include <algorithm>
Forward_iterator remove_if (forward_iterator start, Forward_iterator end, predicate p);

The function remove_if () Removes all elements in the sequence [start, end] that are applied to the predicate p to return true.

This function returns a pointer to the last element iterator of the trimmed sequence.

Remember that remove_if () does not actually remove elements from the sequence [start, end]; If Remove_if () is applied on a container, the length of the container does not change (remove_if () is not possible to change the container's properties only through iterators), and all elements are still inside the container. As a practical practice, remove_if () moves all elements that should be removed to the end of the container and returns a delimited iterator. All of the removed elements can still be accessed through the returned iterator. In order to actually remove the element, you must call erase () on the container itself to erase the element that needs to be removed. This is also the origin of Erase-remove idiom name:

Container.erase (Remove_if (Container.begin (), Container.end (), pred), Container.end ());

remove_if () is similar to Partition (), but with a difference of two points: 1) They use the same predicate conditions exactly the opposite. 2) remove_if only emphasizes the previous part (the second part is no longer needed)

remove_if () runs at linear time (lineartimes).

REMOVE_IF () cannot be used for associative containers such as set<> or map<>.

Original address: http://huycwork.blog.163.com/blog/static/136751999201052044123998/

Std::remove_if

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.