Next: index  Up: index  Previous: 16 Templates  Contents

17 Standard Template Library (STL)

17.1

High Integrity CPP Rule

Use Standard C++ Library headers defined by the language standard and not outdated .h headers. For example, use <iostream> and not <iostream.h>, <cstdio> and not <stdio.h>.

17.2

High Integrity CPP Rule

Use Standard Template Library containers and algorithms in preference to custom designs.

17.3

High Integrity CPP Guideline

Make copying efficient for objects in containers.

17.4

High Integrity CPP Guideline

Where copying is expensive use containers of pointers or smart pointers.

17.5

High Integrity CPP Rule

Do not attempt to insert derived class objects in a container that holds base class objects.

17.6

High Integrity CPP Guideline

Use empty() instead of checking size() against zero.

17.7

High Integrity CPP Guideline

Do not use STL containers as public base classes.

17.8

High Integrity CPP Rule

Never create containers of auto_ptrs.

17.9

High Integrity CPP Rule

Use vector and string in place of dynamically allocated arrays.

17.10

High Integrity CPP Guideline

Where possible pre-allocate in containers to save unnecessary reallocations.

17.11

High Integrity CPP Rule

When passing vector types to C style functions use '&v[ 0 ]'.

17.12

High Integrity CPP Rule

Only use STL string's member c_str to get a const char* to use with legacy functions.

17.13

High Integrity CPP Rule

Do not use vector<bool>.

17.14

High Integrity CPP Rule

Return false for equivalent values in relational predicates.

17.15

High Integrity CPP Rule

Never modify the key part of a set or multiset element.

17.16

High Integrity CPP Guideline

Minimise mixing of iterator types.

17.17

High Integrity CPP Rule

The result of a predicate should depend only on its parameters.

17.18

High Integrity CPP Guideline

Use STL algorithms rather than hand-written loops.

17.19

High Integrity CPP Rule

Use container member functions rather than algorithms with the same name.

17.20

High Integrity CPP Rule

Directly include necessary STL headers.

17.21

High Integrity CPP Guideline

Minimise use of the Standard Template Library 'auto_ptr'.


HICPP VERSION 2.4  http://www.codingstandard.com   Copyright: © 2007 THE PROGRAMMING RESEARCH GROUP