std::experimental::erase_if (std::list)
cppreference.net에서
< cpp | experimental
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 }
참고
| 특정 조건을 만족하는 요소를 제거합니다 (함수 템플릿 & 알고리즘 함수 객체) | |
(C++20)(C++20) |
|
| 특정 조건을 만족하는 요소를 제거합니다 ( std::list<T,Allocator>의 공개 멤버 함수)
| |
(library fundamentals 2 TS) |
특정 값과 동일한 모든 요소를 std::list (함수 템플릿) |