Difference between revisions of "Cpp Coding Standards/The Cpp Standard Template Library"

From Apache OpenOffice Wiki
Jump to: navigation, search
m
Line 1: Line 1:
== The C++ Standard Template Library ==
+
Topic-Id: '''STL'''
 +
 
 
Use and pitfalls of the C++ STL.
 
Use and pitfalls of the C++ STL.
 
----
 
----
 
=== Summary ===
 
=== Summary ===
==== UseContainers ====
+
==== Prefer STL Containers <span id="Cont">(Cont)</span> ====
 
Use STL containers instead of self-made types. In particular, use std::vector instead of Sv*Arrays, std::list instead of DECLARE_LIST etc.
 
Use STL containers instead of self-made types. In particular, use std::vector instead of Sv*Arrays, std::list instead of DECLARE_LIST etc.
  
Line 12: Line 13:
 
You can use vector (and the c_str() function of string classes) to exchange data with non-C++ APIs.  
 
You can use vector (and the c_str() function of string classes) to exchange data with non-C++ APIs.  
  
==== UseAlgorithms ====
+
[[/Cont|Details]]
 +
 
 +
==== Prefer STL Algorithms <span id="Algo">(Algo)</span> ====
 
Prefer STL algorithm calls to handwritten loops.
 
Prefer STL algorithm calls to handwritten loops.
  
==== Erase ====
+
[[/Algo|Details]]
Use the standard idiom to shrink the memory footprint of STL containers
+
  
==== PurePredicates ====
+
==== Erasing Container Memory <span id="EraseMem">(EraseMem)</span> ====
 +
Use the standard idiom to shrink the memory footprint of STL containers.
 +
 
 +
[[/EraseMem|Details]]
 +
 
 +
==== Pure Predicates <span id="PurePred">(PurePred)</span> ====
 
Make predicates pure functions, when used in STL algorithms.
 
Make predicates pure functions, when used in STL algorithms.
  
----
+
[[/PurePred|Details]]
=== Explanations ===
+
  
 
----
 
----
 
[[Category:Coding Standards]]
 
[[Category:Coding Standards]]

Revision as of 22:52, 29 November 2006

Topic-Id: STL

Use and pitfalls of the C++ STL.


Summary

Prefer STL Containers (Cont)

Use STL containers instead of self-made types. In particular, use std::vector instead of Sv*Arrays, std::list instead of DECLARE_LIST etc.

Use std::vector (or an appropriate string class) instead of C-arrays, if there is the slightest chance the array length may ever become variable.

In most cases vector is the best choice for a container.

You can use vector (and the c_str() function of string classes) to exchange data with non-C++ APIs.

Details

Prefer STL Algorithms (Algo)

Prefer STL algorithm calls to handwritten loops.

Details

Erasing Container Memory (EraseMem)

Use the standard idiom to shrink the memory footprint of STL containers.

Details

Pure Predicates (PurePred)

Make predicates pure functions, when used in STL algorithms.

Details


Personal tools