- Apr 16, 2021
- 1 minute
PREMIUM Standard Template Library in C++
Need of STL?
When we develop some applications we have to deal with data. The data is a collection of values and for storing the collection of values we need data structures. CPP provides built-in libraries of classes for all these data structures and that collection of classes are called STL (Standard Template Libraries ).
STL consists of
- Algorithms are the functions used to perform operations on containers
- For example
- A container is a holder object that stores a collection of other objects. They are implemented as class templates, which allows great flexibility in the types supported as elements.
- The container manages the storage space for its elements and provides member functions to access them, either directly or through iterators.
- Many containers have several functions in common, and share functionalities. The decision of which type of container to use for a specific need does not generally depend only on the functionality offered by the container, but also on the efficiency of some of its members
- For example :
- An iterator is any object that, pointing to some element in a range of elements (such as an array or a container), has the ability to iterate through the elements of that range using a set of operators (with at least the increment (
++) and dereference (
- The most obvious form of iterator is a pointer: A pointer can point to elements in an array and can iterate through them using the increment operator (
++). But other kinds of iterators are possible. For example, each container type (such as a list) has a specific iterator type designed to iterate through its elements.
- For example :
Example code with the definition of each container :
Learn with the best. Get access to all existing and future courses and articles created by Tanuj shrivastava.