/////////////////////////////////////////////////////////////// // set3.cpp - demonstrate sets with user defined // // predicate objects // // // // Jim Fawcett, modified 4/4/2000 // /////////////////////////////////////////////////////////////// // disable truncation warnings #pragma warning( disable : 4786 ) #include #include #include ///////////////////////////////////////////////////////////// // #include // // STL containers declare their own simple iterators so, // // you won't need this unless you are doing fancy stuff // ///////////////////////////////////////////////////////////// #include using namespace std; // binary predicate functor equivalent to less // - Uses std::string comparison to return true if first // argument is less than second. // - Will sort set into increasing lexicographic order template class increase { public: bool operator()(const T &t1, const T &t2) { return (t1 class decrease { public: bool operator()(const T &t1, const T &t2) { return (t1>t2); } }; void main(int argc, char *argv[]) { cout << "\nlist of command line arguments in arrival order\n"; int i; for(i=1; i > sos; for(i=1; i >::iterator si; for(si = sos.begin(); si != sos.end(); si++) cout << " " << *si << endl; //////////////////////////////////////////////////////////// // declaring set with greater ordering predicate function // //////////////////////////////////////////////////////////// set< string, decrease > rsos; for(i=1; i >::iterator rsi; for(rsi = rsos.begin(); rsi != rsos.end(); rsi++) cout << " " << *rsi << endl; cout << "\n\n"; }