The Standard Template Library (STL) is a software library for the C++ programming language. It contains the best of the best-inbuilt functions and operators that make code highly optimized.
The Question arises Why STL?
Why to use a separate set of instruction and library functions just to make a code run faster? While we write code, we continuously make decisions and choose between solutions that may seem equivalent at first. Later it usually turns out that some choices result in a more efficient program than others, so a quest for best coding practices and optimization techniques naturally arises, and we begin to see the whole development process as an optimization problem to solve.
Some of the Exclusive benefits of STL are:-
Better Code Readability
More Straightforward Debugging
History of STL:
The architecture of STL is largely the creation of Alexander Stepanov. In 1979 he began working out his initial ideas of generic programming and exploring their potential for revolutionizing software development. Although David Musser had developed and advocated some aspects of generic programming already by year 1971, it was limited to a rather specialized area of software development (computer algebra).
Stepanov recognized the full potential for generic programming and persuaded his then-colleagues at General Electric Research and Development (including, primarily, David Musser and Deepak Kapur) that generic programming should be pursued as a comprehensive basis for software development. At the time there was no real support in any programming language for generic programming.
Components of STL
Containers: – Containers are used to manage collections of objects of a certain kind. There are several different types of containers like deque, list, vector, map etc.
Algorithm: – Algorithms act on containers. They provide the means by which you will perform initialization, sorting, searching, and transforming of the contents of containers. Their main function is to optimize the working of code.
Iterator: – Iterators are used to step through the elements of collections of objects. These collections may be containers or subsets of containers.
Some of the containers which are already present in STL library are: –
Array: – Arrays are fixed-size sequence containers: they hold a specific number of elements ordered in a strict linear sequence.
Internally, an array does not keep any data other than the elements it contains (not even its size, which is a template parameter, fixed on compile time).
Vector: – Vectors are sequence containers representing arrays that can change in size. Just like arrays, vectors use contiguous storage locations for their elements, which means that their elements can also be accessed using offsets on regular pointers to its elements, and just as efficiently as in arrays. But unlike arrays, their size can change dynamically, with their storage being handled automatically by the container.
These are the ones that are mostly used by the programmers.
Algorithm: The header defines a collection of functions especially designed to be used on ranges of elements.
A range is any sequence of objects that can be accessed through iterators or pointers, such as an array or an instance of some of the STL containers.
Some of them are as follows:
Iterator: – They are actually like pointing mechanisms used to point at any particular value in the container they are used to run loops when any container tag is used. They have same data type as of the value stored in the container.
Some of the most important are the forward, backward and the bidirectional iterators. Both of these iterators can be used as either input or output iterators, meaning you can use them for either writing or reading. The forward iterator only allows movement one way — from the front of the container to the back. To move from one element to the next, the increment operator, ++, can be used.
Some of the useful sites and sources where u can find appropriate content to study are :
• C++ Programming Language Tutorials − C++ Programming Language Tutorials.
• C++ Programming − This book covers the C++ programming language, its interactions with software design and real life use of the language.
• Free Country − The Free Country provides free C++ source code and C++ libraries for a number of C++ programming areas including compression, archiving, game programming, the Standard Template Library, and GUI programming.
• C and C++ Users Group − The C and C++ Users Group provides free source code from C++ projects in a variety of programming areas including AI, animation, compilers, databases, debugging, encryption, games, graphics, GUI, language tools, system programming and more.
Note: All rights reserved. No part of this Post may be copied, distributed, or transmitted in any form or by any means, without the prior written permission of the website admin, except in the case of brief quotations embodied in critical reviews and certain other noncommercial uses permitted by copyright law. For permission requests, write to the owner, addressed “Attention: Permissions Coordinator,” to the email@example.com