#include <iostream>
#include <vector>
#include <iterator>
#include <functional>
#include <algorithm>
using namespace std;
template<class Container, class Iterator>
void ShowElement(Container& c, Iterator& itor);
int main()
{
typedef vector<int>::iterator VectorInterator;
vector<int> intValueVector(10);
intValueVector[0] = 0;
intValueVector[1] = 1;
intValueVector[2] = 1;
intValueVector[3] = 2;
intValueVector[4] = 3;
intValueVector[5] = 4;
intValueVector[6] = 1;
intValueVector[7] = 2;
intValueVector[8] = 3;
intValueVector[9] = 5;
vector<int> intValueVector2(3);
intValueVector2[0] = 1;
intValueVector2[1] = 2;
intValueVector2[2] = 3;
VectorInterator first1 = intValueVector.begin();
VectorInterator last1 = intValueVector.end();
VectorInterator first2 = intValueVector2.begin();
VectorInterator last2 = intValueVector2.end();
VectorInterator retItor = find_first_of(first1, last1, first2, last2);
cout << "find_first_of(first1, last1, first2, last2) = ";
ShowElement(intValueVector, retItor);
cout << "\n";
retItor = search(first1, last1, first2, last2);
cout << "search(first1, last1, first2, last2) = ";
ShowElement(intValueVector, retItor);
cout << "\n";
retItor = find_end(first1, last1, first2, last2);
cout << "find_end(first1, last1, first2, last2) = ";
ShowElement(intValueVector, retItor);
cout << "\n";
return 0;
}
template<class Container, class Iterator>
void ShowElement(Container& c, Iterator& itor)
{
if (itor != c.end())
{
if (itor != c.begin())
cout << *itor << "\tthe previous element is " << *(itor - 1);
else
cout << "first";
}
else
cout << "last";
}
|