Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

150 C++ Coding Standards 76. Use vector by default. Otherwise, choose an appropriate container. Summary Using the "right container" is great: If you have a good reason to use a specific con- tainer type, use that container type knowing that you did the right thing. So is using vector: Otherwise, write vector and keep going without breaking stride, also knowing you did the right thing. Discussion Here are three fundamental issues and related questions for programming in gen- eral, and for choosing a container in particular: Write for correctness, simplicity, and clarity first (see Item 6): Prefer to choose the container that will let you write the clearest code. Examples: If you need to in- sert at a specific position, use a sequence container (e.g., vector, list). If you need