Namespaces
Variants

std::experimental::erase_if (std::basic_string)

출처: ko.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/string>
template< class CharT, class Traits, class Alloc, class Pred >
void erase_if( std::basic_string<CharT, Traits, Alloc>& c, Pred pred );
(library fundamentals TS v2)

조건자 pred를 만족하는 모든 요소를 컨테이너에서 삭제합니다. c.erase(std::remove_if(c.begin(), c.end(), pred), c.end());에 해당합니다.

매개변수

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

복잡도

선형.

예제

#include <experimental/string>
#include <iomanip>
#include <iostream>
int main()
{
    std::string data{"1337!p_C00L_<a-_HACKER_!@s_(!s#@_w^o%r*d#42"};
    std::cout << "Original string: " << std::quoted(data) << '\n';
    auto crack = [](auto O) { return '`' ^ ('`' & O); };
    std::experimental::erase_if(data, crack);
    std::cout << "After erase_if:  " << std::quoted(data) << '\n';
}

출력:

Original string: "1337!p_C00L_<a-_HACKER_!@s_{!s#@_w^o%r*d#42"
After erase_if:  "password"

참고

특정 기준을 만족하는 요소를 제거합니다
(함수 템플릿& 알고리즘 함수 객체)
(library fundamentals 2 TS)
특정 값과 같은 모든 요소를 std::basic_string
에서 제거합니다 (function template)