remove_if http://www.cplusplus.com/reference/algorithm/remove_if/
// remove_if example
#include <iostream>
#include <algorithm>
using namespace std;
bool IsOdd (int i) { return ((i%2)==1); }
int main () {
int myints[] = {1,2,3,4,5,6,7,8,9}; // 1 2 3 4 5 6 7 8 9
// bounds of range:
int* pbegin = myints; // ^
int* pend = myints+sizeof(myints)/sizeof(int); // ^ ^
pend = remove_if (pbegin, pend, IsOdd); // 2 4 6 8 ? ? ? ? ?
// ^ ^
cout << "range contains:";
for (int* p=pbegin; p!=pend; ++p)
cout << " " << *p;
cout << endl;
return 0;
}
posted on 2011-07-29 23:17 more think, more gains 阅读(196) 评论(0) 编辑 收藏 举报