共用方式為


list::remove_if (STL/CLR)

移除通過指定的測試的項目。

    template<typename Pred1>
        void remove_if(Pred1 pred);

參數

  • pred
    若要移除的項目進行測試。

備註

成員函式會移除受控制序列 (清除) 每個項目X的pred(X)為 true。 您可以用它來移除全都符合條件指定做為函式或委派的所有項目。

範例

// cliext_list_remove_if.cpp 
// compile with: /clr 
#include <cliext/list> 
 
int main() 
    { 
    cliext::list<wchar_t> c1; 
    c1.push_back(L'a'); 
    c1.push_back(L'b'); 
    c1.push_back(L'b'); 
    c1.push_back(L'b'); 
    c1.push_back(L'c'); 
 
// display initial contents " a b b b c" 
    for each (wchar_t elem in c1) 
        System::Console::Write(" {0}", elem); 
    System::Console::WriteLine(); 
 
// fail to remove and redisplay 
    c1.remove_if(cliext::binder2nd<cliext::equal_to<wchar_t> >( 
        cliext::equal_to<wchar_t>(), L'd')); 
    for each (wchar_t elem in c1) 
        System::Console::Write(" {0}", elem); 
    System::Console::WriteLine(); 
 
// remove and redisplay 
    c1.remove_if(cliext::binder2nd<cliext::not_equal_to<wchar_t> >( 
        cliext::not_equal_to<wchar_t>(), L'b')); 
    for each (wchar_t elem in c1) 
        System::Console::Write(" {0}", elem); 
    System::Console::WriteLine(); 
    return (0); 
    } 
 
  

需求

標頭: < cliext/清單 >

Namespace: cliext

請參閱

參考

list (STL/CLR)

list::clear (STL/CLR)

list::erase (STL/CLR)

list::remove (STL/CLR)

list::unique (STL/CLR)