/* // TEMPLATE FUNCTION find_if template<class _InIt, class _Pr> inline _InIt _Find_if(_InIt _First, _InIt _Last, _Pr _Pred) { // find first satisfying _Pred _DEBUG_RANGE(_First, _Last); _DEBUG_POINTER(_Pred); for (; _First != _Last; ++_First) if (_Pred(*_First)) break; return (_First); } template<class _InIt, class _Pr> inline _InIt find_if(_InIt _First, _InIt _Last, _Pr _Pred) { // find first satisfying _Pred _ASSIGN_FROM_BASE(_First, _Find_if(_CHECKED_BASE(_First), _CHECKED_BASE(_Last), _Pred)); return (_First); } // TEMPLATE FUNCTION adjacent_find template<class _FwdIt> inline _FwdIt _Adjacent_find(_FwdIt _First, _FwdIt _Last) { // find first matching successor _DEBUG_RANGE(_First, _Last); for (_FwdIt _Firstb; (_Firstb = _First) != _Last && ++_First != _Last; ) if (*_Firstb == *_First) return (_Firstb); return (_Last); } template<class _FwdIt> inline _FwdIt adjacent_find(_FwdIt _First, _FwdIt _Last) { // find first matching successor _ASSIGN_FROM_BASE(_First, _Adjacent_find(_CHECKED_BASE(_First), _CHECKED_BASE(_Last))); return (_First); } */ //*********************by vincent http://my.csdn.net/sunboyiris ************************// #include "stdafx.h" #include "algorithm" #include "list" #include "iostream" using namespace std; bool fun(int x) {return x%3?false:true;} int _tmain(int argc, _TCHAR* argv[]) { list<int> l; for(int i=100;i<109;i++) { l.push_back(i); } //引用指针 int count1=0; list<int>::iterator iter; for(iter=l.begin();iter!=l.end();iter++) { count1++; } cout<<count1<<endl; list<int>::iterator iter1=find_if(l.begin(),l.end(),fun); if(iter1!=l.end()) { cout<<"找到元素能被3整除"<<endl; cout<<"前一个元素为:"<<*(--iter1)<<endl; } return 0; }
STL(3) find_if函数
原创
©著作权归作者所有:来自51CTO博客作者王孟贤的原创作品,请联系作者获取转载授权,否则将追究法律责任
下一篇:STL(2)find函数
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章