the philosophy behind of the design of the STL

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.


 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 }

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

时间: 2024-10-15 14:09:34

the philosophy behind of the design of the STL的相关文章

Range-Based for Loops

for ( decl : coll ) { statement } where decl is the declaration of each element of the passed collection coll and for which the statements specified are called. 1. using the initializer list for ( int i : { 2, 3, 5, 7, 9, 13, 17, 19 } ) { std::cout <

Nike Air &#160;Vapormax 2018 Performance Reviews

The new version goes even darker than the original, removing the hint of dark grey Flyknit is releasing this year . Today we are talking about it . it is used the Nike Vapormax Flyknit  technology as well . Nike Flyknit technology was inspired by fee

bullet HashMap 内存紧密的哈希表

last modified time:2014-11-9 14:07:00 bullet 是一款开源物理引擎,它提供了碰撞检测.重力模拟等功能,很多3D游戏.3D设计软件(如3D Mark)使用它作为物理引擎. 作为物理引擎,对速度的要求是非常苛刻的:bullet项目之所以能够发展到今天,很大程度取决于它在速度上优异的表现. 翻阅bullet的源码就能看到很多源码级别的优化,本文将介绍的HashMap就是一个典例. bullet项目首页:http://bulletphysics.org/ 注:b

The history and design philosophy of Spring

spring 历史: 2004年 Spring Framework 1.0 final 正式问世. 1.在Spring1.x时代,都是通过xml文件配置bean,随着项目的不断扩大,需要将xml配置分放到不同的配置文件中,需要频繁的在java类和xml配置文件中切换. 2.随着JDK 1.5带来的注解支持,Spring2.x可以使用注解对Bean进行申明和注入,大大的减少了xml配置文件,同时也大大简化了项目的开发. 3.从Spring3.x开始提供了Java配置方式,使用Java配置方式可以更

Spring history、design philosophy (Spring的历史及设计理念)

一,Spring的发展史 1,Spring1.x 时代 在Spring1.x时代,都是通过xml文件配置bean,随着项目的不断扩大,需要将xml配置分放到不同的配置文件中,需要频繁的在java类和xml配置文件中切换. 2,Spring2.x时代 随着JDK 1.5带来的注解支持,Spring2.x可以使用注解对Bean进行申明和注入,大大的减少了xml配置文件,同时也大大简化了项目的开发. 那么,问题来了,究竟是应该使用xml还是注解呢? 最佳实践: 应用的基本配置用xml,比如:数据源.资

Domain Driven Design and Development In Practice--转载

原文地址:http://www.infoq.com/articles/ddd-in-practice Background Domain Driven Design (DDD) is about mapping business domain concepts into software artifacts. Most of the writings and articles on this topic have been based on Eric Evans' book "Domain Dr

Let it crash philosophy part II

Designing fault tolerant systems is extremely difficult.  You can try to anticipate and reason about all of the things that can go wrong with your software and code defensively for these situations, but in a complex system it is very likely that some

Codelab for Android Design Support Library used in I/O Rewind Bangkok session

At the moment I believe that there is no any Android Developer who doesn't know about Material Design anymore since it officially becomes a design philosophy by shaking the world of design in passed year. Surprisingly that it was not easy to implemen

Codelab for Android Design Support Library

extends:http://inthecheesefactory.com/blog/android-design-support-library-codelab At the moment I believe that there is no any Android Developer who doesn't know about Material Design anymore since it officially becomes a design philosophy by shaking