#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <iostream>
using namespace std;
template <typename InputIterator>
struct _does_not_contain
{
_does_not_contain(InputIterator start,
InputIterator end);
template <typename T>
bool operator()(const T& value);
private:
InputIterator s, e;
};
template <typename InputIterator>
_does_not_contain<InputIterator>
does_not_contain(InputIterator start,
InputIterator end);
template <typename T>
bool always_false(const T& v) { return false; }
int main()
{
vector<string> names[4];
names[0].push_back("Chris");
names[0].push_back("Bob");
names[0].push_back("John");
names[1].push_back("Francis");
names[1].push_back("Cole");
names[1].push_back("John");
names[1].push_back("Chris");
remove_copy_if(
names[0].begin(), names[0].end(),
back_inserter(names[2]),
does_not_contain(names[1].begin(), names[1].end()));
remove_copy_if(
names[1].begin(), names[1].end(),
back_inserter(names[2]),
does_not_contain(names[0].begin(), names[0].end()));
sort(names[2].begin(), names[2].end());
unique_copy(names[2].begin(), names[2].end(), back_inserter(names[3]));
copy(names[3].begin(), names[3].end(),
ostream_iterator<string>(cout, "\n"));
return 0;
}
template <typename InputIterator>
_does_not_contain<InputIterator>::_does_not_contain(InputIterator start,
InputIterator end)
: s(start), e(end)
{
}
template <typename InputIterator>
template <typename T>
bool _does_not_contain<InputIterator>::operator()(const T& value)
{
return find(s, e, value) == e;
}
template <typename InputIterator>
_does_not_contain<InputIterator>
does_not_contain(InputIterator start,
InputIterator end)
{
return _does_not_contain<InputIterator>(start, end);
}
|