beautypg.com

HP Integrity NonStop H-Series User Manual

Page 16

background image

It is very important to know that iterators can become invalidated as a result of a
subsequent insertion or deletion from the underlying container class. This invalidation is
not checked, and use of an invalid iterator can produce unexpected results.

Familiarity with the Standard C++ Library will help reduce the number of errors related
to iterators.

Templates: Errors and "Code Bloat"

The flexibility and power of templatized algorithms are, with most compilers, purchased
at a loss of precision in diagnostics. Errors in the parameter lists to generic algorithms
will sometimes show up only as obscure compiler errors for internal functions that are
defined many levels deep in template expansions. Again, familiarity with the algorithms
and their requirements is a key to successful use of the standard library.

Because of its heavy reliance on templates, the STL can cause programs to grow larger
than expected. You can minimize this problem by learning to recognize the cost of
instantiating a particular template class, and by making appropriate design decisions. Be
aware that as compilers become more and more fluent in templates, this will become less
of a problem.

Multithreading Problems

The Standard C++ Library must be used carefully in a multithreaded environment.
Iterators, because they exist independently of the containers they operate on, cannot be
safely passed between threads. Since iterators can be used to modify a non const
container, there is no way to protect such a container if it spawns iterators in multiple
threads. Use "thread-safe" wrappers, such as those provided by Tools.h++, if you need to
access a container from multiple threads.

This manual is related to the following products: