STL Algorithm 之 find
2017-04-13 00:00
169 查看
find_if
template<class InputIterator, class Predicate> InputIterator find_if( InputIterator _First, InputIterator _Last, Predicate _Pred );
Parameters
_First
An input iterator addressing the position of the first element in the range to be searched.
_Last
An input iterator addressing the position one past the final element in the range to be searched.
_Pred
User-defined predicate function object that defines the condition to be satisfied by the element being searched for. A predicate takes single argument and returns true or false.
Return Value
An input iterator that addresses the first element in the range that satisfies the condition specified by the predicate.
find
template<class InputIterator, class Type> InputIterator find( InputIterator _First, InputIterator _Last, const Type& _Val );
Parameters
_First
An input iterator addressing the position of the first element in the range to be searched for the specified value.
_Last
An input iterator addressing the position one past the final element in the range to be searched for the specified value.
_Val
The value to be searched for.
Return Value
An input iterator addressing the first occurrence of the specified value in the range being searched. If no such value exists in the range, the iterator returned addresses the last position of the range, one past the final element.
find_first_of
template<class ForwardIterator1, class ForwardIterator2> ForwardIterator1 find_first_of( ForwardIterator1 _First1, ForwardIterator1 _Last1, ForwardIterator2 _First2, ForwardIterator2 _Last2 ); template<class ForwardIterator1, class ForwardIterator2, class BinaryPredicate> ForwardIterator1 find_first_of( ForwardIterator1 _First1, ForwardIterator1 _Last1, ForwardIterator2 _First2, ForwardIterator2 _Last2, BinaryPredicate _Comp );
Parameters
_First1
A forward iterator addressing the position of the first element in the range to be searched.
_Last1
A forward iterator addressing the position one past the final element in the range to be searched.
_First2
A forward iterator addressing the position of the first element in the range to be matched.
_Last2
A forward iterator addressing the position one past the final element in the range to be matched.
_Comp
User-defined predicate function object that defines the condition to be satisfied if two elements are to be taken as equivalent. A binary predicate takes two arguments and returns true when satisfied and false when not satisfied.
Return Value
A forward iterator addressing the position of the first element of the first subsequence that matches the specified sequence or that is equivalent in a sense specified by a binary predicate.
Remarks
The operator== used to determine the match between an element and the specified value must impose an equivalence relation between its operands.
The ranges referenced must be valid; all pointers must be dereferenceable and, within each sequence, the last position is reachable from the first by incrementation.
find_end
template<class ForwardIterator1, class ForwardIterator2> ForwardIterator1 find_end( ForwardIterator1 _First1, ForwardIterator1 _Last1, ForwardIterator2 _First2, ForwardIterator2 _Last2 ); template<class ForwardIterator1, class ForwardIterator2, class Pr> ForwardIterator1 find_end( ForwardIterator1 _First1, ForwardIterator1 _Last1, ForwardIterator2 _First2, ForwardIterator2 _Last2, BinaryPredicate _Comp );
Parameters
_First1
A forward iterator addressing the position of the first element in the range to be searched.
_Last1
A forward iterator addressing the position one past the final element in the range to be searched.
_First2
A forward iterator addressing the position of the first element in the range to be searched.
_Last2
A forward iterator addressing the position one past the final element in the range to be searched.
_Comp
User-defined predicate function object that defines the condition to be satisfied if two elements are to be taken as equivalent. A binary predicate takes two arguments and returns true when satisfied and false when not satisfied.
Return Value
A forward iterator addressing the position of the first element of the last subsequence that matches the specified sequence or that is equivalent in a sense specified by a binary predicate.
Remarks
The operator== used to determine the match between an element and the specified value must impose an equivalence relation between its operands.
The ranges referenced must be valid; all pointers must be dereferenceable and, within each sequence, the last position is reachable from the first by incrementation.
#include <iostream> #include <vector> using namespace std; bool cmp(int& a) { return a > 100; } bool match(int &a ,int &b) { return a == b; } int main() { vector<int> test; test.push_back(20); test.push_back(4); test.push_back(123); test.push_back(4); vector<int>match_table; match_table.push_back(1); match_table.push_back(2); match_table.push_back(3); match_table.push_back(4); vector<int>::iterator i; if ((i = find_if(test.begin(), test.end(), cmp)) != test.end()) cout << (i - test.begin()) << "--->" << *i << endl; if ((i = find_if_not(test.begin(), test.end(), cmp)) != test.end()) cout << (i - test.begin()) << "--->" << *i << endl; if ((i = find(test.begin(), test.end(), 4)) != test.end()) cout << (i - test.begin()) << "--->" << *i << endl; if ((i = find_first_of(test.begin(), test.end(), match_table.begin(), match_table.end())) != test.end()) cout << (i - test.begin()) << "--->" << *i << endl; if ((i = find_first_of(test.begin(), test.end(), match_table.begin(), match_table.end(), match)) != test.end()) cout << (i - test.begin()) << "--->" << *i << endl; if ((i = find_end(test.begin(), test.end(), match_table.begin(), match_table.end(),match)) != test.end()); cout << (i - test.begin()) << endl; getchar(); return 0; }
相关文章推荐
- Can not find the tag library descriptor for "http://java.sun.com/jsp/jstl/
- mxmlc FLEX命令行编译swf 提示could not find JRE
- linux 命令 which whereis find locate
- LINUX 下 find grep sed awk 的常见基本用法特点
- c/c++字符串处理-split/trim/find/rfind/substr/strstr
- 【搜索】【poj 1426】Find The Multiple
- Jetty9 NO JSP Support for /, did not find org.apache.jasper.servlet.JspServlet
- hdu - 2645 find the nearest station (bfs水)
- POJ 1703 Find themCatch them
- notepad++ 查找引用(Find Reference)(适用于c c++及各类脚本比如lua、python等)
- 'You've got to find what you love,' Jobs says
- FindControl 找控件
- Unable to find a java Virtual Machine ---- Oracle Developer
- 【CentOS】比较有用的find系列工具
- transform.Find() sends null value的解决方案
- find的详细用法及其例子
- Linux文件查找命令find
- rails s时报错:Could not find a JavaScript runtime
- find 总结
- 浅谈jQuery中find()与filter()两种方法联系与区别