//: C05:Removing.cpp // From Thinking in C++, 2nd Edition // Available at http://www.BruceEckel.com // (c) Bruce Eckel 2000 // Copyright notice in Copyright.txt // The removing algorithms #include "PrintSequence.h" #include "Generators.h" #include #include #include using namespace std; struct IsUpper { bool operator()(char c) { return isupper(c); } }; int main() { vector v(50); generate(v.begin(), v.end(), CharGen()); print(v, "v", ""); // Create a set of the characters in v: set cs(v.begin(), v.end()); set::iterator it = cs.begin(); vector::iterator cit; // Step through and remove everything: while(it != cs.end()) { cit = remove(v.begin(), v.end(), *it); cout << *it << "[" << *cit << "] "; print(v, "", ""); it++; } generate(v.begin(), v.end(), CharGen()); print(v, "v", ""); cit = remove_if(v.begin(), v.end(), IsUpper()); print(v.begin(), cit, "after remove_if", ""); // Copying versions are not shown for remove // and remove_if. sort(v.begin(), cit); print(v.begin(), cit, "sorted", ""); vector v2; unique_copy(v.begin(), cit, back_inserter(v2)); print(v2, "unique_copy", ""); // Same behavior: cit = unique(v.begin(), cit, equal_to()); print(v.begin(), cit, "unique", ""); } ///:~