P75 find()函数处理array、vector、list的区别。
#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<iterator>
using namespace std;
int main()
{
const int asize = 8;
int ia[asize] = {
1, 1, 2, 3, 4, 5, 13, 21 };
vector<int> ivec = {
ia, ia + asize };
list<int> ilist = {
ia, ia + asize };
int *pia = find(ia, ia + asize, 1024);
if (pia != ia + asize)
cout << "find it1 " << endl;
else
cout << "not find it1" << endl;
vector<int>::iterator iv;
iv = find(ivec.begin(), ivec.end(), 13);
if (iv != ivec.end())
cout << "find it2 " << endl;
else
cout << "not find it2" << endl;
list<int>::iterator il;
il = find(ilist.begin(), ilist.end(), 1024);
if (il != ilist.end())
cout << "find it3 " << endl;
else
cout << "not find it3" << endl;
system("pause");
return 0;
}
3.6小节 造轮子之filter()
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
using namespace std;
template<typename InputIterator,typename OutputIterator,typename ElemType, typename Comp>
OutputIterator filter(InputIterator first, OutputIterator last, OutputIterator at, const ElemType &val, Comp pred)
{
while