#include <iostream>
#include <list>
#include <algorithm>
using namespace std;
int main()
{
list<int> listObject(10);
list<int>::iterator p;
int *ip, *ip_end;
int nums[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
int i;
cout << "Initial contents of nums: ";
for(i = 0; i <10; i++)
cout << nums[ i ] << " ";
cout << endl;
copy(nums, &nums[9], listObject.begin()); // copy nums array to list
cout << "Contents of listObject after copy: ";
for(p=listObject.begin(); p!=listObject.end(); p++)
cout << *p << " ";
cout << endl;
ip_end = remove_copy_if(listObject.begin(), // remove elements that are less than 5
listObject.end(),
nums,
bind2nd(less<int>(),
5));
cout << "Contents of nums after remove_copy_if(): ";
for(ip=nums; ip!=ip_end; ip++)
cout << *ip << " ";
return 0;
}
|