Imitation function and function Adapter

Source: Internet
Author: User
//// 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.