C + + Primer Learning summary 9th Chapter sequential Container

Source: Internet
Author: User

9th Chapter Sequential Container


1. Sequential containers If you have a default constructor that requires only the container size parameter , the function uses the element's default constructor to construct each element object, and if the container's elements do not have a default constructor , then You cannot use this constructor for this container P294:


2. When a container is copied, the elements of the two containers must be of the same type.

However, if the list is initialized, or the iterator scope initializes the container, only the elements or iterators in the list are required to be converted to the elements of the container.

3. The container type can be assigned directly by the = sign (including the array container type):

Note: Assign only applies to sequential containers (but not to array)


4. Two containers for = = or! = are compared by the = = operator of the element. They perform a > or < comparison using the < operator of the element, So if the element does not define either operator or the two operators are not public , then you will not be able to compare :

5. The sequential container (except array) supports insert (P307), the following is the use of insert:

Use Insert The return value : Insert () returns an iterator to the first element it inserts .

6. Use the Emplace operation:

7. In addition to forward_list, other sequential containers support front () and back () operations, but P311 Books say they return references , But my test results are not so , where is the problem ?

Let's look at another way:

Description Front () and the Back () does return a reference , but Auto There is no correct type of parsing .

at The action also returns a reference Oh .

8. Vector Delete element p311-312


9. The resize () operation supports all sequential containers except array, which can either increase the element or reduce the element of the container, if the element is deleted, the iterator that may result in the element being deleted, the pointer, the reference is invalidated:

Add character of string, delete character operation: P322


11. Using resize () to increase the container does not change the value of the original element in the container:

C + + Primer Learning summary 9th Chapter sequential Container

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.