C++primer the Nineth Chapter

Source: Internet
Author: User

//1.vector: Variable size array. Fast random access is supported, and inserting or deleting elements at a location outside the trailer can be slow. //deque: Double-ended queue. Supports fast random access, inserting or deleting elements quickly at the tail. //list: Doubly linked list. Only bidirectional sequential access is supported. Inserting or deleting elements at any location is quick. //forward_list: One-way linked list. Only one-way sequential access is supported. Inserting or deleting elements at any location is quick. //string: A container similar to a vector, designed to hold characters. Support for random access. Inserting or deleting elements at the tail is quick. //2. The vector is usually selected, and when it is not sure which container to use, then only the iterator is used, which makes it convenient to replace the container. //3. If the container element type does not have a default constructor, when the size parameter is provided for this container, you must also provide an initial value for the displayed element (the initial value of the displayed element must be constructed into the element type of the container). classctest{ Public: CTest (inti): value (i) {}Private:    intvalue;}; Vector<CTest> Vectest (2,Ten);//vectest = [2] ({value=10},{value=10})Vector<ctest> VecTest1 (2);//error, no incoming initial valueVector<ctest> VecTest2;//correct//4. Type alias operations for common containers://iterator: Iterator type for this container//const_iterator: Read-only iterator type//size_type: Unsigned, enough to hold the maximum possible container size for this type of container. Under 32-bit programs, 4 bytes and 64-bit programs are 8 bytes. //Difference_type: With symbolic shaping, enough to hold the distance between two iterators. Under 32-bit programs, 4 bytes and 64-bit programs are 8 bytes. //Value_type: The type of element that the container is stored in. //Reference: The reference type of the element that the container is stored in. Equivalent to value_type&//Const_reference: The constant reference type of the element that the container is stored in. Equivalent to const value_type&//5. The meaning of the various operations is reversed when compared to a forward iterator by a reverse iterator. For example, + + will get the previous element of the reverse iterator. //6. You can copy the elements in the A container into the B container, as long as the element type of the A container can be converted to the element type of the B containerlist<Double>Listdouble;listdouble.emplace_back (1.1); Listdouble.emplace_back (2.2); Vector<int> Vecint (Listdouble.begin (), Listdouble.end ());//vecint = [2]vector<int>vecint1;vecint1.assign (Listdouble.begin (), Listdouble.end ()); //vecInt1 = [2]//Note: The assign operation of the container also has a usage: vecint1.assign (2,1); //vecInt1 = [2] (a)//7. When you change the element of the container, note that the iterator, pointer, and reference to the container element may be invalidated. For example, the assignment of containers can result in the above results. You should reposition iterators, pointers, and references each time you change the operation of the container. //8. A function of the Emplace series of a container, which creates an element with the given parameters (if it is not a built-in type, calls its constructor), while the push_back or Push_front function copies an element by value (the constructor of the element is not actively invoked). Insert performance In this regard is consistent with the Push_back series functions. vector<unique_ptr<Char[]>>Vecstr;vecstr.emplace_back (New Char[Ten]());//LegalVecstr.push_back (New Char[Ten]());//illegalVecstr.insert (Vecstr.begin (),New Char[Ten]());//vs2010, although legal, but syntactically speaking, this sentence is wrong. //9. The container cannot hold references to elements. //10. The general container provides the front () and back () member functions, which are used to return a reference to the end and end elements, respectively. The General container provides an at () member function, which is similar to the subscript operator, but the former is more capable of judging if the subscript is out of bounds, and throws a Out_of_range exception if it crosses the border. //11. Insert and delete operations for unidirectional linked list forward_list: Insert_after,emplace_after,erase_after. Since the one-way list can conveniently get its next member and cannot get its previous member, its insert and delete operations are different from other containers, and the corresponding Before_begin returns the first-forward iterator of the unidirectional list. //12. The Resize member function makes it easy to change the size of the container and supports incoming initialization parameters for newly added elements. //common operations for 13.string classes://c_str (): Returns a string of type const char*//substr: Returns a string of the specified length from the specified position in the specified string//Find : Finds the position of the first occurrence of the specified sequence after the specified position//RFind: Finds the location of the last occurrence of the specified sequence after the specified position//find_first_of: Finds the position of the element in the sequence for the first occurrence of the specified sequence after the specified position//find_last_of: Finds the position of the element in the sequence for the last occurrence of the specified sequence after the specified position//find_first_not_of: Finds the position of the first element not in the specified sequence after a specified position//find_last_not_of: Finds the position of the last element not in the specified sequence after the specified position//Replace : Replaces the element in the specified sequence with another element in the specified sequence//14. Container adapter: A container adapter can accept an existing container type, making its behavior look like a different type. //stack: defined in the header file stack and operated at the top of the stack. //Supported Actions: Pop (), push (), Emplace (), Top ()//It is implemented by default using Deque, or it can be implemented on a list or vector. //queue: defined in the header file queue, whose elements are FIFO first. The entry element is placed at the end of the team and deleted at the head of the team. //operation: Pop (), front (), Back (), push (), emplace ()//the deque implementation is used by default and can be implemented with list and vector. //priority_queue: defined in the header file queue. Allows us to prioritize the elements in the queue. By default < is used to determine relative priority (from large to small). //Supported Actions: Pop (), push (), Emplace (), Top (). Note: Top () returns the highest-priority element in Priority_queue. Support for random access. //vectors are implemented by default, and can be implemented using Dequestack<int, vector<int>> Staint;//use a non-default container to construct the container adapter. //A .//begin (), end () + +//begin () End ()//    | |//v v//aaaaaaaaaaaaaaaaa//   ^                ^//   |    | //rend () rbegin ( )//rend (), Rbegin ()---> 

C++primer the Nineth Chapter

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.