The Standard Template Library

  This information may be updated soon.

The Standard Template Library (STL) is an important feature of the ANSI C++ standard. Unfortunately, The programmer's guide to C++ was published just too early to include a satisfactory description of its many features. Future editions of the book will correct this omission, but for the moment here are some sources of information about the STL:

The latest versions of many C++ compilers are now being shipped with the STL, which includes C++ strings. If the library is correctly implemented, it should be used with namespaces and the new header file naming convention as discussed in the update, namespaces and string sections at this site.

Some compilers that are not shipped with the STL might still be able to use it. However, a version of the library will have to installed, and the compiler's development environment setup to know were it is. If you want to try to do this, the Silicon Graphics STL is a worthwhile looking at, and Warren Young's resource list mentions lots of other sources of STL implementations.


This and That....

Using STL functions that take function pointers as parameters can cause problems when the function being passed is templated. Take this function for example:

template< class T >
void justPrint( const T& x )
   std::cout << x << " ";

We can pass it to an STL function like this:


This will compile, but in some environments a link error will be reported because an instance of the function cannot be found. In this case, we can force instantiation with

void xxx()

This xxx function is never called, but its definition forces an instance of justPrint<int> to be created, and this prevents the error. The trick is to call the template function with the same type of argument that the STL function will use. In this example an integer value is just what is needed. There are other ways to manage this, but a dummy function is the simplest work-around.