//// Main. CPP // function_adaptor // created by IDM-PKU on 14-9-3. // copyright (c) 2014 PKU. all rights reserved. // # include <iostream> # include <set> # include <deque> # include <algorithm> # include "print. HPP "using namespace STD; int main (INT argc, const char * argv []) {set <int, greater <int> coll1; deque <int> coll2; for (INT I = 1; I <= 9; ++ I) {coll1.insert (I);} print_elements (coll1, "initialized:"); transform (coll1.begin (), coll1.end (), back_inserter (coll2), bind2nd (multiplies <int> (), 10); print_elements (coll2); replace_if (coll2.begin (), coll2.end (), bind2nd (performance_to <int> (), 70), 42); print_elements (coll2, "Replace:"); coll2.erase (remove_if (coll2.begin (), coll2.end (), bind2nd (less <int> (), 50), coll2.end (); print_elements (coll2, "removed:"); Return 0 ;}
//// Print. HPP // function_adaptor // created by IDM-PKUSZ on 14-9-3. // copyright (c) 2014 PKU. all rights reserved. // # ifndef feature # define function_adaptor_print_hpp # include <iostream> template <class T> inline void print_elements (const T & Coll, const char * optcstr = ") {typename T :: const_iterator Pos; STD: cout <optcstr; For (Pos = Coll. begin (); pos! = Coll. End (); ++ POS) STD: cout <* POS <''; STD: cout <STD: Endl;} # endif
Through some special function adapters, you can combine pre-defined functions and other numeric values.
The following is the running result of Mac OS:
Imitation function and function Adapter