Introduction to C + + Standard Template Library __c++

Source: Internet
Author: User

A library is a collection of program components that can be reused in different programs. The first requirement of library function design is universality, and the template (template) brings immeasurable prospect for universality.

The Standard Template Library (Standard Template Library), abbreviated as STL, is one of the most characteristic and practical parts of Ansi/iso C + +. STL includes: Container Class (Container), Iteration sub (iterator), Algorithm (algorithm)

Generic algorithms (generic algorithm) and function objects (functions object) enable the algorithm to get rid of the dependency on individual manipulation of different data types.
Introduction to the Standard Template Library

1. Container Class (Container)
A container class is a class that manages a sequence, a class that holds a set of objects or objects. By using the member functions provided by the container class, you can implement actions such as inserting elements into a sequence, deleting elements, finding elements, and so on, which specify the position of the element in the sequence by returning the iteration child.

Containers are grouped into three main categories: Sequential containers (Sequence Container or sequential Container) associated containers (associative Container) container adapters (Container adopter)

Sequential and associative containers are called first class containers (first-class container), as shown in the following table.

The container provides a similar interface. Many of the basic operations are applicable to all containers, while others apply to a subset of similar containers and can be extended using new classes with similar operations. See table 11.2 Functions shared by all standard library containers

2. Generic algorithm (Generic algorithm)
In a template the algorithm does not depend on the specific data type, and the generic algorithm goes further than the concrete container.

In the generic algorithm, the function object is used to introduce the difference of the same algorithm in different cases. It does not use inheritance and polymorphism, avoids the overhead of virtual functions, and makes the STL more efficient.

3, iterative sub (iterator)
An iterator is a generic form of the pointer concept that points to an element in a container that can be added or subtracted like a pointer, indicating each element in a container in turn. So the iteration is a pointer to an object-oriented version.

Iterations can include pointers, but iterations are more than just a pointer.

The iterative subroutine joins the algorithm with the container. The algorithm only indirectly through the iteration of the container element, the algorithm itself and the container Independent. The algorithm usually returns an iteration.

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.