Containers The STL contains sequence
containers and associative containers. The containers are objects that store data. The standard
sequence containers include , , and . The standard
associative containers are , , , , , , and . There are also
container adaptors , , and , that are containers with specific interface, using other containers as implementation.
Iterators The STL implements five different types of
iterators. These are
input iterators (that can only be used to read a sequence of values),
output iterators (that can only be used to write a sequence of values),
forward iterators (that can be read, written to, and move forward),
bidirectional iterators (that are like forward iterators, but can also move backwards) and
s (that can move freely any number of steps in one operation). A fundamental STL concept is a
range which is a pair of iterators that designate the beginning and end of the computation, and most of the library's algorithmic templates that operate on data structures have interfaces that use ranges. It is possible to have bidirectional iterators act like random-access iterators, so moving forward ten steps could be done by simply moving forward a step at a time a total of ten times. However, having distinct random-access iterators offers efficiency advantages. For example, a vector would have a random-access iterator, but a list only a bidirectional iterator. Iterators are the major feature that allow the generality of the STL. For example, an algorithm to reverse a sequence can be implemented using bidirectional iterators, and then the same implementation can be used on lists, vectors and
deques. User-created
containers only have to provide an iterator that implements one of the five standard iterator interfaces, and all the algorithms provided in the STL can be used on the container. This generality also comes at a price at times. For example, performing a search on an
associative container such as a map or set can be much slower using iterators than by calling member functions offered by the container itself. This is because an associative container's methods can take advantage of knowledge of the internal structure, which is opaque to algorithms using iterators.
Algorithms A large number of algorithms to perform activities such as searching and sorting are provided in the STL, each implemented to require a certain level of iterator (and therefore will work on any container that provides an interface by iterators). Searching algorithms like and use
binary search and like sorting algorithms require that the type of data must implement comparison operator or custom comparator function must be specified; such comparison operator or comparator function must guarantee
strict weak ordering. Apart from these, algorithms are provided for making heap from a range of elements, generating lexicographically ordered permutations of a range of elements, merge sorted ranges and perform
union,
intersection,
difference of sorted ranges.
Functions The STL includes classes that
overload the function call operator (). Instances of such classes are called functors or
function objects. Functors allow the behavior of the associated function to be parameterized (e.g. through arguments passed to the functor's
constructor) and can be used to keep associated per-functor state information along with the function. Since both functors and function pointers can be invoked using the syntax of a function call, they are interchangeable as arguments to templates when the corresponding parameter only appears in function call contexts. A particularly common type of functor is the
predicate. For example, algorithms like take a
unary predicate that operates on the elements of a sequence. Algorithms like sort, partial_sort, nth_element and all sorted
containers use a
binary predicate that must provide a
strict weak ordering, that is, it must behave like a
membership test on a transitive, non-reflexive and asymmetric
binary relation. If none is supplied, these algorithms and containers use less by default, which in turn calls the less-than-operator <. == Criticisms ==