std::experimental:: erase_if (std::list)
From cppreference.net
<
cpp
|
experimental
|
헤더 파일에 정의됨
<experimental/list>
|
||
|
template
<
class
T,
class
Alloc,
class
Pred
>
void erase_if ( std:: list < T, Alloc > & c, Pred pred ) ; |
(라이브러리 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>
의 public 멤버 함수)
|
|
|
(library fundamentals 2 TS)
|
std::list
에서 특정 값과 같은 모든 요소들을 삭제함
(함수 템플릿) |