C++ STL

 

C++ STL

 

What is Standard Template Library?

Competitive programming is a part of various environments, be it job interviews, coding contests, and all, and if you’re in one of those environments, you’ll be given limited time to code your program. So, suppose you want in your program, a resizable array, sort an array or any other data structure. or search for some element in your container. You will always try to code a function that will execute the above-mentioned things, and end up losing a great amount of time. But here is when you will use STL. 

 

An STL is a library of generic functions and classes which saves you time and energy which you would have spent constructing for your use. This helps you reuse these well-tested classes and functions an umpteenth number of times according to your own convenience. To put this simply, STL is used because it is not a good idea to reinvent something which is already built and can be used to innovate things further. Suppose you go to a company that builds cars, they will not ask you to start from scratch, but to start from where it is left. This is the basic idea behind using STL.

 

What are the components of STL?

  • Containers

Container is an object that stores data. We have different containers having their own benefits. These are the implemented class templates for our use, which can be used just by including this library. You can even customize these template classes.

 

  • Algorithm

Algorithms are sets of instructions that manipulate the input data to arrive at some desired result. In STL, we have already written algorithms, for example, to sort some data structure, or search some element in an array. These algorithms use function templates. 

 

  • Iterators

Iterators are objects which refer to an element in a container. And we handle them very much similar to a pointer. Their basic job is to connect algorithms to the container and play a vital role in the manipulation of the data.