38typedef std::ostream_iterator<int, char, std::char_traits<char> >
50 std::cout <<
"Remove Algorithm examples" << std::endl;
53 int data[] = { 1, 2, 4, 3, 1, 4, 2 };
54 std::list<int, std::allocator<int> > aList;
56 std::copy (
data,
data+7, std::inserter (aList, aList.begin ()));
57 std::cout <<
"Original list: ";
58 std::copy (aList.begin (), aList.end (),
61 std::cout << std::endl;
64 std::list<int, std::allocator<int> > newList;
66 std::remove_copy (aList.begin (), aList.end (),
67 std::back_inserter (newList), 2);
68 std::cout <<
"After removing 2's: ";
69 std::copy (newList.begin (), newList.end (),
72 std::cout << std::endl;
75 std::list<int, std::allocator<int> >::iterator
76 where = std::remove (aList.begin (), aList.end (), 2);
78 std::cout <<
"List after removal, before erase: ";
79 std::copy (aList.begin (), aList.end (),
82 std::cout << std::endl;
84 aList.erase (where, aList.end ());
85 std::cout <<
"List after erase: ";
86 std::copy (aList.begin (), aList.end (),
89 std::cout << std::endl;
92 where = std::remove_if (aList.begin (), aList.end (),
isEven);
93 aList.erase (where, aList.end ());
95 std::cout <<
"List after removing even values: ";
96 std::copy (aList.begin (), aList.end (),
99 std::cout << std::endl;
107 int data[] = { 1, 3, 3, 2, 2, 4 };
108 std::list<int, std::allocator<int> > aList;
110 std::copy (
data,
data+6, std::inserter (aList, aList.begin ()));
111 std::cout <<
"Origianal List: ";
112 std::copy (aList.begin (), aList.end (),
116 std::cout << std::endl;
119 std::set<int, std::less<int>, std::allocator<int> > aSet;
121 std::unique_copy (aList.begin (), aList.end (),
122 std::inserter (aSet, aSet.begin ()));
124 std::cout <<
"Set after unique_copy: ";
125 std::copy (aSet.begin (), aSet.end (),
ostrm_iter_type (std::cout,
" "));
127 std::cout << std::endl;
130 std::list<int, std::allocator<int> >::iterator
131 where = std::unique (aList.begin (), aList.end ());
133 std::cout <<
"List after calling unique: ";
134 std::copy (aList.begin (), aList.end (),
137 std::cout << std::endl;
140 aList.erase (where, aList.end ());
142 std::cout <<
"List after erase: ";
143 std::copy (aList.begin (), aList.end (),
146 std::cout << std::endl;
152 std::cout <<
"STL generic algorithms -- Removal Algorithms"
158 std::cout <<
"End of removal algorithms sample program"
std::ostream_iterator< int, char, std::char_traits< char > > ostrm_iter_type
std::ostream_iterator< int, char, std::char_traits< char > > ostrm_iter_type