a C++ library of container classes, algorithms, and iterators
STL is a generic library, meaning that its components are heavily parameterized: almost every component in the STL is a template.
STL includes container classes: classes whose purpose is to contain other objects. The STL includes the classes vector, list, deque, set, multiset, map, multimap, hash_set, hash_multiset, hash_map, and hash_multimap. Each of these classes is a template, and can be instantiated to contain any type of object.
STL also includes collection of algorithms that manipulate the data stored in containers. algorithms are decoupled from the STL container classes.
iterators are a generalization of pointers. Iterators are the mechanism that makes it possible to decouple algorithms from containers: algorithms are templates, and are parameterized by the type of iterator, so they are not restricted to a single type of container.
Concepts and Modeling
One very important question to ask about any template function is what the set of types is that may correctly be substituted for the formal template parameters. These requirements are sufficiently important that we give them a name: we call such a set of type requirements a concept, and we call this particular concept Input Iterator. We say that a type conforms to a concept, or that it is a model of a concept, if it satisfies all of those requirements. We say that int* is a model of Input Iterator because int* provides all of the operations that are specified by the Input Iterator requirements.
Refinement
Refinement of concepts is very much like inheritance of C++ classes; the main reason we use a different word, instead of just calling it "inheritance", is to emphasize that refinement applies to concepts rather than to actual types. The main purpose is to impose additional requirements.
Other parts of STL
the STL includes several utilities: very basic concepts and functions that are used in many different parts of the library. The concept Assignable, for example, describes types that have assignment operators and copy constructors; almost all STL classes are models of Assignable, and almost all STL algorithms require their arguments to be models of Assignable.
Some low-level mechanisms for allocating and deallocating memory: Allocator
the STL includes a large collection of function objects, also known as functors. Just as iterators are a generalization of pointers, function objects are a generalization of functions: a function object is anything that you can call using the ordinary function call syntax. Function objects are an important part of generic programming because they allow abstraction not only over the types of objects, but also over the operations that are being performed.
Reference:
http://www.sgi.com/tech/stl/stl_introduction.html
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment