다음을 통해 공유


list::remove_if

지정된 조건자를 만족하는 목록에서 요소를 지웁니다.

template<class Predicate> 
void remove_if( 
   Predicate _Pred 
)

매개 변수

  • _Pred
    삭제 목록에서 요소에 요소를 만족하는 경우 결과에 단정합니다.

예제

// list_remove_if.cpp
// compile with: /EHsc
#include <list>
#include <iostream>

template <class T> class is_odd : public std::unary_function<T, bool> 
{
public:
   bool operator( ) ( T& val ) 
   {
   return ( val % 2 ) == 1;
   }
};

int main( ) 
{
   using namespace std;
   list <int> c1;
   list <int>::iterator c1_Iter, c2_Iter;
   
   c1.push_back( 3 );
   c1.push_back( 4 );
   c1.push_back( 5 );
   c1.push_back( 6 );
   c1.push_back( 7 );
   c1.push_back( 8 );

   cout << "The initial list is c1 =";
   for ( c1_Iter = c1.begin( ); c1_Iter != c1.end( ); c1_Iter++ )
      cout << " " << *c1_Iter;
   cout << endl;
   
   list <int> c2 = c1;
   c2.remove_if( is_odd<int>( ) );

   cout << "After removing the odd elements, "
        << "the list becomes c2 =";
   for ( c2_Iter = c2.begin( ); c2_Iter != c2.end( ); c2_Iter++ )
      cout << " " << *c2_Iter;
   cout << endl;
}
  

요구 사항

헤더: <목록>

네임스페이스: std

참고 항목

참조

list 클래스

표준 템플릿 라이브러리