Namespaces
Variants

std::experimental::erase_if (std::set)

cppreference.net에서

 
 
실험적
기술 사양
파일 시스템 라이브러리 (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)
실험적 비TS
패턴 매칭
선형 대수학
std::execution
계약
2D 그래픽
 
 
헤더에 정의됨 <experimental/set>
template< class Key, class Compare, class Alloc, class Pred >
void erase_if( std::set<Key, Compare, Alloc>& c, Pred pred );
(library fundamentals TS v2)

조건자를 만족하는 모든 요소를 제거합니다 pred 컨테이너에서 제거합니다. 다음과 동일합니다

for (auto i = c.begin(), last = c.end(); i != last;)
{
    if (pred(*i))
        i = c.erase(i);
    else
        ++i;
}

매개변수

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

복잡도

선형.

예제

#include <experimental/set>
#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::set<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:
{ 0 1 2 3 4 5 6 7 }
Erase all items divisible by 3:
{ 1 2 4 5 7 }

같이 보기

특정 기준을 만족하는 요소들을 제거합니다
(함수 템플릿 & 알고리즘 함수 객체)