Top of document
©Copyright 1999 Rogue Wave Software

Extending the Library

The adoption of the Standard Library for C++ marks a very important development for users of the C++ programming language. Although the library is written in an OOP language and provides plenty of objects, it also employs an entirely different paradigm. This other approach, called "generic programming," provides a flexible way to apply generic algorithms to a wide variety of different data structures. The flexibility of C++ in combination with this synthesis of two advanced design paradigms results in an unusual and highly-extensible library.

The clearest example of this synthesis is the ability to extend the library with user-defined containers and algorithms. This extension is possible because the definition of data structures has been separated from the definition of generic operations on those structures. The library defines very specific parameters for these two broad groups, giving users some confidence that containers and algorithms from different sources will work together as long as they all meet the specifications of the standard. At the same time, containers encapsulate data and a limited range of operations on that data in classic OOP fashion.

Each standard container is categorized as one of two types: a sequence or an associative container. A user-defined container need not fit into either of these two groups since the standard also defines rudimentary requirements for a container, but the categorization can be very useful for determining which algorithms will work with a particular container and how efficiently those algorithms will work. In determining the category of a container, the most important characteristics are the iterator category and element ordering. (The Tutorial and Reference Guide sections on each container describe the container types and iterator categories.)

Standard algorithms can be grouped into categories using a number of different criteria. The most important of these are: 1) whether or not the algorithm modifies the contents of a container; 2) the type of iterator required by the algorithm; and 3) whether or not the algorithm requires a container to be sorted. An algorithm may also require further state conditions from any container it's applied to. For instance, all the standard set algorithms not only require that a container be in sorted order, but also that the order of elements was determined using the same compare function or object that will be used by the algorithm.


Top of document