The transform of C++STD function

Source: Internet
Author: User

/*Template < class Inputiterator, class Outputiterator, Class Unaryoperator > Outputiterator transform (Inputiterator first1,//start address of source container inputiterator Last1,/ /End address of the source container outputiterator result,//start address of the target container Unaryopera     Tor op);          function pointer//typedef target CONTAINER element type (*unaryoperator) (source container element type);       Template < class InputIterator1, class InputIterator2, Class Outputiterator, Class Binaryoperator > Outputiterator transform (InputIterator1 first1,//Starting address of Source container 1 InputIterator1 las                                 T1,//termination address of source container 1 InputIterator2 first2,//start address of source container 2, number of elements same as 1 Outputiterator result,//destination container start address, number of elements same as 1 Binaryoperator binary_op ); function pointer//typedef target CONTAINER element type (*binaryoperator) (source container 1 element type, source capacity2 element type); //*////////////////////////////////  #include<iostream>#include<algorithm>#include<vector>#include<string>using namespacestd; intOp_increase (inti) {returni+1; }            intOp_sum (intIintj) {returni+J; }            intTo_upper (intc) {if(Islower (c)) {return(C- +); }                returnC; }            intTo_lower (intc) {if(Isupper (c)) {returnc+ +; }                returnC; }            intmain () {vector<int>First ; Vector<int>second; Vector<int>:: Iterator it; //set some values:         for(intI=1; i<6; i++) First.push_back (i*Ten);//first:10                  ///assigns the element of the first container plus 1 to the second containerSecond.resize (First.size ());//Allocate space!!! Must be pre-set to the same size as firstTransform (First.begin (), First.end (), Second.begin (), op_increase);//second:11cout <<"Second contains:";  for(It=second.begin (); It!=second.end (); + +it) {cout<<" "<< *it; } cout<<Endl; //*////////////////////////////////////////////                    ///Adds the elements of the first container to the elements of the second container and assigns the resulting results back to the firstTransform (First.begin (), First.end (), Second.begin (), First.begin (), op_sum);//first:21, Bayi 101cout <<"First contains:";  for(It=first.begin (); It!=first.end (); + +it) cout<<" "<< *it; cout<<Endl; //*//////////////////////////////////////////////////////////////////////////                ///uppercase and lowercase conversions/////////////////////////////////////          stringSTRSRC ("Hello, world!."); stringstrdest;      Strdest.resize (Strsrc.size ()); // !!! Must be pre-set to the same size as StrsrcTransform (Strsrc.begin (), Strsrc.end (), Strdest.begin (), to_upper);//Convert to uppercasecout << strdest <<Endl; Transform (Strsrc.begin (), Strsrc.end (), Strdest.begin (), to_lower); //Convert to lowercasecout << strdest <<Endl; //*/////////////////////////////////////////                return 0; }

The transform of C++STD function

Related Article

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.