Standard Template Library
DRAFT
-
The standard template library (STL) is the heart of the C++ standard library. The STL is a generic library that provides solutions to managing collections of data with efficient algorithms.
-
The main components of STL that are provided to us as programming tools are algorithms and containers.
-
Usually, if we want to support A algorithms and C containers, we’d need A × C implementation. (For each container c, we would have to implement A algorithms.)
-
One solution to this is to use polymorphism. But it would decrease efficiency.
-
STL’s solution to this problem is to use iterators. Each container is required to provide iterators and each algorithm is implemented to work with iterators. As a result, STL needs to provide only A + C implementations for A algorithms and C containers.
-
There are many reasons to use the STL, so use it whenever you can in C++!
-
It allows to reuse already existing code. No need to reinvent the wheel!
-
It’s been optimized and is probably more efficient than your implementations of algorithms and data structures would be.
-
It’s most likely to be less buggy that the code you (initially) write.
-
The STL is standardized and is guaranteed to be available with C++ standard library.
-
Using it will provide you with a good knowledge of data structures and algorithms.
-