Program :
Code:
#include <algorithm>
#include <functional>
#include <iostream>
#include <vector>
int main ()
{
typedef std::vector<int, std::allocator<int> > vector;
const vector::value_type a1[] =
{
0, 1, 2, 2, 3, 4, 2, 2, 6, 7
};
const vector::value_type a2[] = { 6, 4 };
const vector v1(a1, a1 + sizeof a1 / sizeof *a1);
const vector v2(a2, a2 + sizeof a2 / sizeof *a2);
vector::const_iterator it1 =
std::find_first_of(v1.begin(), v1.end(),
v2.begin(), v2.end());
vector::const_iterator it2 =
std::find_first_of(v1.begin(), v1.end(),
v2.begin(), v2.end(),
std::equal_to<vector::value_type>());
std::ostream_iterator<vector::value_type, char,
std::char_traits<char> > out(std::cout, " " );
std::cout << "For the vectors { ";
std::copy(v1.begin(), v1.end(), out);
std:: cout << "} and { ";
std::copy(v2.begin(), v2.end(), out);
std::cout << "}\nboth versions of find_first_of "
<< "point to: " << *it1 << std::endl;
return !(*it1 == *it2);
}
Output :
Code:
For the vectors { 0 1 2 2 3 4 2 2 6 7 } and { 6 4 }
both versions of find_first_of point to: 4
Bookmarks