Functions and Application of Six STL components

Source: Internet
Author: User

STL provides six components that can be combined and used together:

1 container: various data structures, such as vector, list, deque, set, and map, are used to store data. From the implementation perspective, STL container is a class template, in terms of volume, this part is similar to the ratio of the iceberg under the cape.

2 algorithms (algorithms): common algorithms such as sort, search, copy, and erase .... From the implementation point of view, STL algorithm is a function template.

Iterators: acts as the glue between containers and algorithms. It is called a generic pointer. There are five types and other derivative changes. From the implementation point of view, the iterator is a class template that reloads pointer-related operations such as operator *, operator->, operator ++, and operator. Therefore, STL containers come with their own exclusive iterators. Yes, only container designers know how to traverse their own elements. Native pointer is also an iterator.

4. functors: a function with similar behavior can be used as a policy of an algorithm. From the implementation perspective, A function is a class or class template with operateor [] reloaded. Generally, function pointers can be regarded as narrow imitation functions.

Adapters: an interface used to modify containers, functors, or iterators. For example, the queue and stack provided by STL, although seemingly a container, can only be regarded as a container adapter. Because they use deque at the bottom, all operations are supplied by the deque at the bottom, which changes the functor interface, called the function adapter; the container interface, called the container adapter; and The iterator interface, it is called the iterator adapter.

6. configurator: responsible for space configuration and management. From the perspective of implementation, the Configurator is a class template that implements dynamic space configuration, space management, and space release.

Interaction between these six components: the container (container) acquires the data storage space through Allocator (configurator), and the algorithm (algorithm) accesses the content of the container (container) through the iterator (iterator, functor helps algorithm (algorithm) to implement different policy changes, and the adapter can modify or intercept functor (function simulation ). For example:

 

Functions and Application of Six STL components

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.