码迷,mamicode.com
首页 > 其他好文 > 详细

the philosophy behind of the design of the STL

时间:2014-05-26 09:43:55      阅读:288      评论:0      收藏:0      [点我收藏+]

标签:des   style   c   class   blog   code   

The concept of STL is based on a separation of data and operations. The data is managed by container classes, and the operations are defined by configurable algorithms. Iterators are the glue between these two components and they let any algorithm interact with any container.

bubuko.com,布布扣 

 

 

bubuko.com,布布扣
 1 template<T>
 2 Print(List<T> & container)
 3 {
 4     for(T item: container)
 5     {
 6         //...
 7     }
 8 }
 9 
10 template<T>
11 Print(iterator<T> begin, iterator<T> end)
12 {
13     for(;begin < end && begin != end; begin ++)
14     {
15         //...
16     }
17 }
bubuko.com,布布扣

 

The STL concept contradicts the original idea of object-oriented programming: the STL serarates data and algorithms rather than combining them. While you can combine every kinds of container with ever kind of algorithm, so the result is a very flexible but still rather small framework.

The particular implementation of any container is not defined by the C++ standard library. However, the behavior and complexity secified by the standard do not leave much room for variation.

The STL containers provide only those special member functions that in general have "good" performance, where "good" normal means constant or logarithmic complexity. e.g., a direct element access by using operator [] is not provided for lists. This is because lists don‘t provide random access, and so an operator [] would have bad performance.

Which is also most like why there is no resize() for array. 

 

 

 

the philosophy behind of the design of the STL,布布扣,bubuko.com

the philosophy behind of the design of the STL

标签:des   style   c   class   blog   code   

原文地址:http://www.cnblogs.com/Cmpl/p/3747328.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!