C + + Primer 5th notes: Nineth Chapter

Source: Internet
Author: User

Nineth chapter: Sequential containers

Notes

1. A container is a collection of certain types of objects. Sequential Container (sequential Container) provides programmers with the ability to control the order in which elements are stored and Accessed.

2. Containers are divided into ordered containers and unordered containers ; Access is divided into sequential access and random access .

3. Forward_list and array are the added types of the new C + + Standard. Array is a more secure and easy-to-use array type than a built-in array. Similar to built-in arrays, the size of an array object is Fixed.

4. In general, using vectors is the best choice unless you have good reason to choose another container.

5. Type aliases in container operations: iterator, const_iterator, size_type, difference_type, value_type, Reference (left value of element type), const_reference ( The const lvalue type of the element).

6. An iterator range (iterator Range) is represented by a pair of iterators, with two iterators pointing to an element in the same container or to the position after the trailing Element. This element range is called the left closing interval (left-inclusive interval), and the mathematical form is [begin, end].

7. If you need an element type, you can use the value_type of the Container. If you need a reference to the element type, you can use reference or Const_reference. These element-related type aliases are useful in generic programming.

8. Begin () and end () have multiple versions, the version with R returns a reverse iterator, and the version beginning with C returns a const ITERATOR. Functions that do not start with C are Overloaded. When we call these members on a very object, we get the version that returns Iterator. A const version is only available when these functions are called on a const OBJECT.

9. When no write access is required, use Cbegin () and Cend ().

10. Standard library Array:

array<int>      //   type: holds a value of 42 int array<string  >   //  type: Save 10 Arrays of string

One. the operands of the left and right sides of the relational operator must be containers of the same type and must hold elements of the same type.

12. It is important to understand that different containers use different strategies to allocate element space, and these policies directly affect performance .

13. The new standard introduces three new members Emplace_front,emplace , and emplace_back, which write operations rather than copy Elements.

//constructs a Sales_data object at the end of CC.emplace_back ("978-059035", -,15.99);//Sales_data constructors that use three parametersC.push_back ("978-059035", -,15.99);//error: push_back function with three parameters not acceptedC.push_back (sales_data ("978-059035", -,15.99);//correct: Create a temporary Sales_data object to pass to the Push_back

The Emplace function directly constructs the function in the Container. The arguments passed to the Emplace function must match the constructor of the element type.

14. The container operation may invalidate the Iterator.

15. Do not save the iterator returned by the End.

Terms

Adapter (adaptor), Container (container), iterator range (iterator range), left closing interval (left-inclusive interval)

C + + Primer 5th notes: Nineth Chapter

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.