Learning STL: walking from micro to macro

In STL, the data container and algorithms are separated from each other for more inner cohesion without any considering and involving with each other. However, this separation leads a problem that is the algorithms do not know or get the type of data stored in container. The container and iterator must reflect or transmit these information of data type, meta-data of data type, to the algorithms which could use these traits to do more work, for example defining local variable with the type of embedded in the container. Algorithms just concentrate on the utilizing of iterator and extract the traits of data provided by iterator and container.

Also, this leads another importance in programming that is the meta-data of type  or information of data type which can be used as data in different parts of a program.

Both basic knowledge and practice and analysis of data structure and algorithms as well as the understanding of C++ templates and operators overloading and STL code structure are needed to really master the STL and get the tricks of STL programming.  

Understanding of iterator: refining the concept of pointer to deal with heap memory 

In terms of the practical heap memory allocating of the container, the smart pointer is a better choice to manage the heap memory. The essence of container which is implemented in heap memory is linked pieces of heap memory. Connected with shared_ptr and unique_ptr, iterator is a kind of smart pointer(not ordinary), overloading more operators, such as the operator++ and operator-- and operator* and operator->, managing the container, but would not automatically free the dynamic heap memory sometimes. The job of freeing the heap memory is delegated to the container of nodes and data. In short, the iterators, grouped concepts, are new abstract generic concepts needed by algorithms, wrapping the different data type with some requirements, capturing the common reality, which can be modeled at least by built-in pointer.

Iterator could do the looping work and provide service to algorithms: getting the pointer of node and grabbing the user’s data out of the node and returning the data back to the application. What the algorithms care about is the data that user puts into the node and container. Iterator must provide the interfaces of inputting data and outputting data just like a smart pointer does.  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值