怎么使用STL中的list:remove_if()函数呀
如何使用STL中的list::remove_if()函数呀
list::remove_if()函数的参数是怎么回事,我有点看不懂,有哪位高手给我指教下,最好给出完整的简洁实例。谢谢各位了!
------解决方案--------------------
看看这个
http://blog.csdn.net/steven_wang787/archive/2009/09/03/4513121.aspx
------解决方案--------------------
list::remove_if()函数的参数是怎么回事,我有点看不懂,有哪位高手给我指教下,最好给出完整的简洁实例。谢谢各位了!
------解决方案--------------------
看看这个
http://blog.csdn.net/steven_wang787/archive/2009/09/03/4513121.aspx
------解决方案--------------------
- C/C++ code
#include <iostream> #include <list> using namespace std; // a predicate implemented as a function: bool single_digit (const int& value) { return (value<10); } // a predicate implemented as a class: class is_odd { public: bool operator() (const int& value) {return (value%2)==1; } }; int main () { int myints[]= {15,36,7,17,20,39,4,1}; list<int> mylist (myints,myints+8); // 15 36 7 17 20 39 4 1 mylist.remove_if (single_digit); // 15 36 17 20 39 mylist.remove_if (is_odd()); // 36 20 cout << "mylist contains:"; for (list<int>::iterator it=mylist.begin(); it!=mylist.end(); ++it) cout << " " << *it; cout << endl; return 0; }
------解决方案--------------------
指定要移除哪个值的判定函数.
该函数返回值为bool类型.用于指定哪个值是要删除的.
------解决方案--------------------
++
------解决方案--------------------
template <class T>
class functor
{
public:
bool operator() (T* rhs){return true, //if match your condition, false if dont}
}
remove_if(con.begin(), con.end(), functor);