// This file, part of a series, show why functors are so cool, // because they can maintain state information: // - from the constructor // - from call-to-call // // This code uses a functor to remove all vowels from the name. // Note that it uses remove_copy_if instead of remove_copy. #include #include #include #include #include using namespace std; class IsVowel { public: bool operator()(char c) const { return string("aeiouyAEIOUY").find(c) != string::npos; } }; int main() { char name[] = "James Tiberius Kirk"; remove_copy_if(name, name+strlen(name), ostream_iterator(cout), IsVowel()); cout << '\n'; }