Difference between revisions of "Cpp Coding Standards/STL"

From Apache OpenOffice Wiki
Jump to: navigation, search
(formatting)
Line 1: Line 1:
Topic-Id: '''STL'''
+
=== The C++ Stnadard Template Library (STL) ===
 +
''Use and pitfalls of the C++ STL.''
  
Use and pitfalls of the C++ STL.
+
===== 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::vector (or in very rare cases std::list) instead of DECLARE_LIST etc.<br>
=== Summary ===
+
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.<br>
==== Prefer STL Containers <span id="Cont">(Cont)</span> ====
+
In most cases vector is the best choice for a container.<br>
Use STL containers instead of self-made types. In particular, use std::vector instead of Sv*Arrays, std::list instead of DECLARE_LIST etc.
+
You can use vector (and the c_str() function of string classes) to exchange data with non-C++ APIs.<br>
 +
[[/Cont|-> Details]]
  
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.
+
===== Erasing Container Memory <span id="EraseMem">(EraseMem)</span> =====
 +
Use the standard idiom to shrink the memory footprint of STL containers. [[/EraseMem|-> Details]]
  
In most cases vector is the best choice for a container.
+
===== Pure Predicates <span id="PurePred">(PurePred)</span> =====
 
+
Make predicates pure functions, when used in STL algorithms. [[/PurePred|-> Details]]
You can use vector (and the c_str() function of string classes) to exchange data with non-C++ APIs.
+
 
+
[[/Cont|Details]]
+
 
+
==== 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.
+
 
+
[[/PurePred|Details]]
+
  
 
----
 
----
 
[[Category:Coding Standards]]
 
[[Category:Coding Standards]]

Revision as of 18:58, 22 May 2007

The C++ Stnadard Template Library (STL)

Use and pitfalls of the C++ STL.

Prefer STL Containers (Cont)

Use STL containers instead of self-made types. In particular, use std::vector instead of Sv*Arrays, std::vector (or in very rare cases 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

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