13 Oktober, 2009

The 11 Standard Template Library (STL) Headers

Headers for the STL "sequence containers"

<deque>

This header provides a double-ended queue container, with fast insertion and deletion at both ends and (somewhat counterintuitively to the abstract notion of queueness) direct access to any element.

<list>

This header provides a sequence container with fast performance when adding elements to, or removing elements from, any point in the sequence, but with only sequential access to any particular element.

<vector>

This header provides the vector container, which is best thought of as a generalized array, capable of "growing and shrinking" as the occasion demands. Vectors provide fast insertion and deletion at one end, and direct access to any element.

Headers for the STL "associative containers"

<map>

This header provides map and multimap classes which store key-value pairs. The map requires unique keys, but the multimap permits duplicate keys.

<set>

This header provides set and multiset classes which store keys. The set can store only unique keys, but the multiset permits duplicate keys.

Headers for the STL "container adaptors"

<queue>

This header provides containers which are actually "adapted" sequential containers and provide the usual FIFO behavior of a standard queue structure, as well as "priority queue" behavior.

<stack>

This header provides a container which is actually one of the above containers "adapted" to provide the usual LIFO behavior of a stack structure.

Headers for the STL algorithms

<algorithm>

This header provides a large number (about 70, depending on how you count) generic algorithm function templates for operating on iterators, as well as some other objects such as "function objects" that help algorithms to perform their tasks. It is part of the genius, power and flexibility of the STL that these algorithms do not operate on containers directly, but on iterators that point to containers. This means that under quite general conditions, the same algorithm can operate on several different containers, and in a variety of ways, which is, of course, the whole point of "generic programming".

<numeric>

This header declares a small number (four) of function templates specifically for numerical algorithms.

Headers for the STL iterators and function objects

<iterator>

This header provides classes and templates for defining and using iterators, though it does not have to be included if you are just using one or more of the sequential and/or associative containers and their associated iterators, since those iterators will be available from the container classes themselves.

<functional>

This header defines several function objects. These may also be called functionals, or functors. A function object is an object of a class that implements operator(). This permits the function object to be "called", using the same syntax as a function, to help an algorithm perform its task. But, because it is an object, it is more versatile than a function.

Miscellaneous STL headers

<memory>

This header declares functions and class templates for allocating and using memory. The average programmer will not need to include this header, since the default container "allocators" are perfectly adequate most of the time. Programmers who are developing their own containers, iterators and algorithms will be more inclined to find a use for what's in this header.

<utility>

This header declares the pair<> template, which is essential when using maps and multimaps, but also finds many uses in everyday programming. Though it may or may not be of interest to the average programmer, this header also defines the rel-ops namespace, which in turn defines relational operators in terms of == and <.

0 komentar:

Posting Komentar