C + + sequential container Learning-Container Adapter

Source: Internet
Author: User

Summary:

A question about the container adapter.

Just beginning to contact the container adapter, always feel strange, think superfluous, handy search, originally I was not alone at this point:

Use of STL container adapters

One of the guys said well, here's a quote:

1 adapter intended to be a receptacle, adapter, the meaning of the coupling. Now I need a stack structure, we can use deque to do, only one end of the element insertion and ejection, the other end does not move. This means that deque can be used as a stack structure, but it does not directly meet your requirements, because you cannot prevent others from moving your stuff on the other end. You need to wrap it up and make some restrictions so that it can only be inserted and deleted at one end. That means you have to provide a "socket", the "socket" on the deque, the other end in your program, you can use the stack structure. And the stack is the "socket" that connects the Deque and your program. On the surface you are using a stack, in fact you are using the "socket" of the stack to use Deque (because the stack is completely implemented with deque, it does not have anything else, it is just a layer of packaging on the deque, the equivalent of a "socket" function). Therefore, classes such as stack, queue, and priority_queue are generally referred to as container adapters, and they are simply adaptations of the basic container type (vector,dequeue,list).  2     Actually, this is also the basic idea of the adapter pattern: to convert the interface of a class into another interface that the customer wants. The adapter mode makes it possible for those classes that would otherwise not work together because of incompatible interfaces to work together. In other words, a "socket" class is provided on the interface of a class to make it the interface you want to use.

C + + sequential container Learning-Container Adapter

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.