4th Chapter C++STL Generic Library Overview

Source: Internet
Author: User

/*the second C++stl Generalization Technology Foundation 4th Chapter C++STL Generic Library Overview 4.1 C++stl's development history 4.2 C++stl of various implementations version 4.3 C++STL architecture of Visual C + + compilation 4.4 C++stl Some problems existing in 4.5 C++stl 4.6 Chapter Summary The second part of C++stl Generalization Technology 4th Chapter C++STL Generic Library Overview 4.1 c++stl development History 4.2 C++stl various implementations 4.2.1 HP STL 4.2 .2 SGI STL 4.2.3 STLport 4.2.4 P.j.plauger STL 4.2.5 Rouge Wave stl 4.3 C++stl of Visual C + + compiled 4.4 c++stl architecture 4. 4.1 Container (Container) 4.4.2 iterator (Iterator) 4.4.3 algorithm (algorithm) 4.4.4 functions object (function Object) 4.4.5 adapter (Adapter) 4.4.6 inside Storage Allocator (Allocator) 4.4.7 concept (Concept) and model 4.5 C++stl There are some problems 4.6 Chapter summary*///4th Chapter C++STL Generic Library Overview//The development course of 4.1 c++stl---------------------------------------------------------------------------------------//various implementations of the 4.2 C++stl--------------------------------------------------------------------------------------- //4.3 C++stl's Visual C + + compilation------------------------------------------------------------------------------------- --//Wuyi#include <vector>#include<iostream>#include<string>intMainvoid){  using namespacestd; Vector<string>VEC; Vector<string>:: Const_iterator i; Vec.push_back ("Dog"); Vec.push_back ("Bird"); Vec.push_back ("Girl"); Vec.push_back (" Boy"); Vec.push_back ("Hello,there");  for(i = Vec.begin (); I! = Vec.end (); + +i) {cout<< (*i) <<Endl; }  return 0;}//Architecture of 4.4 c++stl---------------------------------------------------------------------------------------// Wu#include <vector>#include<iostream>#include<algorithm>using namespacestd;intMainvoid) {vector<int>v; V.push_back (6); V.push_back (8); V.push_back ( to); Vector<int>::iterator result=Find (V.begin (), V.end (),8); cout<< *result <<Endl; return 0;}// -//bind1st (not_equal_to<int> (), 0)Template <classOperation>classbinder1st: Publicunary_function<typename Operation::second_argument_type, TypeName operation::result_type>{  protected: Operation op;  TypeName Operation::first_argument_type value;  Public: binder1st (Const_operation &x,ConstTypeName Operation::first_argument_type &y): OP (x), value (y) {}//constructor function. Not_equal_to->op 0->valueTypeName Operation::result_typeoperator()      (ConstTypeName _operation::second_argument_type &x)Const    {        returnOP (value, x);//0 not_equal_to x    }}; //my test, bind#include <vector>#include<iostream>#include<algorithm>using namespacestd;intMainvoid) {vector<int>v; V.push_back (1); V.push_back (Ten); V.push_back ( -); size_t I=count_if (V.begin (), V.end (), bind2nd (less_equal<int> (),Ten));//How many <=10 are there? 2 xcout << i <<Endl; return 0;}//my test, bind2nd//It can be seen that the examples in the book are wrong. bind1st (not_equal_to<int> (), 0), No. Value, should be in the first position#include <vector>#include<iostream>#include<algorithm>using namespacestd;intMainvoid) {vector<int>v; V.push_back (1); V.push_back (Ten); V.push_back ( -); size_t I=count_if (V.begin (), V.end (), bind2nd (not_equal_to<int> (),Ten));//How many!=10 are there? 2 xcout << i <<Endl; return 0;}/*C + + primer14.8. Call operators and Function objects The standard library defines two binder adapters: bind1st and bind2nd. Each binder accepts a function object and a value. As you might think, bind1st binds the given value to the first argument of a two-tuple function object, bind2nd binds the given value to the second argument of a two-tuple function object. The standard library also defines two counter converters: Not1 and Not2. As you might have thought, not1 the truth of the Unary function object, not2 the truth of the two-element function object. Here, the second operand of the Less_equal object is first bound to 10, which in effect translates the two-dollar operation into a unary operation. */#include<vector>#include<iostream>#include<algorithm>using namespacestd;intMainvoid) {vector<int>v; V.push_back (1); V.push_back (Ten); V.push_back ( -); size_t I=count_if (V.begin (), V.end (), Not1 (bind2nd (not_equal_to<int> (),Ten)));//How many are not!=10? 1 xcout << i <<Endl; return 0;}//Some problems existed in 4.5 C++stl--------------------------------------------------------------------------------------- //4.6 Summary of this chapter---------------------------------------------------------------------------------------

TOP

4th Chapter C++STL Generic Library Overview

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.