Namespaces
Variants

std::experimental::erase_if (std::list)

cppreference.net에서

 
 
Experimental
기술 명세서
파일 시스템 라이브러리 (filesystem TS)
라이브러리 기초 (library fundamentals TS)
라이브러리 기초 2 (library fundamentals TS v2)
라이브러리 기초 3 (library fundamentals TS v3)
병렬 처리 확장 (parallelism TS)
병렬 처리 확장 2 (parallelism TS v2)
동시성 확장 (concurrency TS)
동시성 확장 2 (concurrency TS v2)
개념 (concepts TS)
범위 (ranges TS)
반영 (reflection TS)
수학 특수 함수 (special functions TR)
Experimental 비TS
패턴 매칭
선형 대수
std::execution
계약
2D 그래픽
 
 
template< class T, class Alloc, class Pred >
void erase_if( std::list<T, Alloc>& c, Pred pred );
(library fundamentals TS v2)에 정의됨

컨테이너에서 조건자 pred를 만족하는 모든 요소를 제거합니다. c.remove_if(pred);와 동일합니다.

매개변수

c - 삭제할 컨테이너
pred - 삭제할 요소를 결정하는 조건자

복잡도

선형.

예제

#include <experimental/list>
#include <iostream>
template<typename Os, typename Container>
inline Os& operator<<(Os& os, Container const& container)
{
    os << "{ ";
    for (const auto& item : container)
        os << item << ' ';
    return os << '}';
}
int main()
{
    std::list<int> data{3, 3, 4, 5, 5, 6, 6, 7, 2, 1, 0};
    std::cout << "Original:\n" << data << '\n';
    auto divisible_by_3 = [](auto const& x) { return (x % 3) == 0; };
    std::experimental::erase_if(data, divisible_by_3);
    std::cout << "Erase all items divisible by 3:\n" << data << '\n';
}

출력:

Original:
{ 3 3 4 5 5 6 6 7 2 1 0 }
Erase all items divisible by 3:
{ 4 5 5 7 2 1 }

참고

특정 조건을 만족하는 요소를 제거합니다
(함수 템플릿 & 알고리즘 함수 객체)
특정 조건을 만족하는 요소를 제거합니다
(std::list<T,Allocator>의 공개 멤버 함수)
(library fundamentals 2 TS)
특정 값과 동일한 모든 요소를 std::list
(함수 템플릿)