stl的find、find_if简单demo
2013-07-13 19:48
197 查看
#include <stdio.h> #include <deque> #include <algorithm> using namespace std; class A { public: int m_nA; void print() { printf("%d\n", m_nA); } bool operator==(const A& a) { return a.m_nA == m_nA; } }; class A_filter { public: A_filter(const A& a) { this->a.m_nA = a.m_nA; } bool operator()(const A& a) { return a.m_nA == a.m_nA; } A a; }; class B { public: void search1(const A& a) { m_nIter = std::find(m_nList.begin(), m_nList.end(), a); m_nIter->print(); } void search2(const A& a) { m_nIter = std::find_if(m_nList.begin(), m_nList.end(), A_filter(a)); m_nIter->print(); } deque<A> m_nList; deque<A>::iterator m_nIter; }; int main() { A a1, a2, a3; B b; a1.m_nA = 1; a2.m_nA = 2; a3.m_nA = 3; b.m_nList.push_back(a1); b.m_nList.push_back(a2); b.m_nList.push_back(a3); b.search1(a1); b.search1(a3); return 0; }
相关文章推荐
- STL find_if demo
- STL_算法_查找算法(find、find_if)
- (STL)for_each、find_if用法
- C++之STL(五):非变动性算法源代码分析与使用示例( for_each、min_element 、find_if、search 等)
- STL_算法_查找算法(find、find_if)
- stl.find_if用法总结
- stl::find_if用法总结
- STL 之 find find_if
- STL中泛型算法find_if()与sort()的应用举例及详解
- stl.find_if用法总结
- STL find_if应用及其他
- STL算法find,find_if,find_if_not,sort,fill,for_each,count,adjacent_find,random_shuffle,prev_permutation
- STL应用 vector & find_if
- c++ stl algorithm: std::find, std::find_if
- 关于在STL容器list中使用find_if搜索特定的节点
- STL之vector,数组线性容器array,list容器,算法find,find_if,bind1st,仿函数
- STL 之find & find_if
- 从零开始学C++之STL(五):非变动性算法源代码分析与使用示例( for_each、min_element 、find_if、search 等)
- 关于在STL容器list中使用find_if 函数
- 【C++ STL学习之七】STL算法之find和find_if