c++ stl library 学习(9)
来源:互联网 发布:拦截软件广告的软件 编辑:程序博客网 时间:2024/05/21 07:06
Requirements for Container Elements:
1. An element must be copyable by a copy constructor.能够被复制构造函数复制
2. An element must be assignable by the assignment operator能够被赋值操作符操作
3 An element must be destroyable by a destructor. Containers destroy their internal copies
of elements when these elements are removed from the container. Thus, the destructor
must not be private. Also, as usual in C++, a destructor must not throw; otherwise, all
bets are off.
容器中不能存放auto_ptr类型的元素。
元素的Value语义和Reference语义:
All containers create internal copies of their elements and return copies of those elements. This
means that container elements are equal but not identical to the objects you put into the
container. If you modify objects as elements of the container, you modify a copy, not the original
object
Copying values means that the STL containers provide value semantics. They contain the values
of the objects you insert rather than the objects themselves. In practice, however, you also need
reference semantics. This means that the containers contain references to the objects that are
their elements.Reference语义就是指容器包含能够指向容器内部元素的引用。
STL只支持Value语义不支持Reference语义。但是可以通过reference counting来实现Reference语义、
Errors and Exceptions Inside the STL:
Error Handling:
In particular, the use of the STL requires that the following be met:
• Iterators must be valid. For example, they must be initialized before they are used. Note
that iterators may become invalid as a side effect of other operations. In particular, they
become invalid for vectors and deques if elements are inserted or deleted, or reallocation
takes place.
• Iterators that refer to the past-the-end position have no element to which to refer. Thus,
calling operator * or operator -> is not allowed. This is especially true for the return
values of the end() and rend() container member functions.
• Ranges must be valid:
o Both iterators that specify a range must refer to the same container.
o The second iterator must be reachable from the first iterator.
• If more than one source range is used, the second and later ranges must have at least as
many elements as the first one.
• Destination ranges must have enough elements that can be overwritten; otherwise, insert
iterators must be used.
Exception Handling:
- c++ stl library 学习(9)
- c++ stl library 学习(1)
- c++ stl library 学习(2)
- c++ stl library 学习(3)
- c++ stl library 学习(4)
- c++ stl library 学习(5)
- c++ stl library 学习(6)
- c++ stl library 学习(7)
- c++ stl library 学习(8)
- C Runtime Library 与 STL
- 标准模板库(Standard Template Library,STL)学习
- STL(Standard Template Library)
- C++STL学习(10)STL算法(1)
- C++STL学习(11)STL算法(2)
- C++STL学习(1)容器vector
- C++STL学习(2)容器deque
- C++STL学习(3)容器list
- C++STL学习(8)迭代器
- 回溯法___批处理调度
- HTTP 错误 404.17 - Not Found 请求的内容似乎是脚本,因而将无法由静态文件处理程序来处理
- 如果你懂,请不要只看到他的笑,你要看到他心底的泪
- js数组操作
- 当用户盘空间满,导致无法编辑mms
- c++ stl library 学习(9)
- 微博分享接口
- 如何实现彩信保存文本用电子书可以正常打开
- linux 环境下Tomcat中查看logs日志
- 如何实现Video Record的时候来新的MMS 仍然可以有提示
- web.xml中配置servlet
- file_get_contents和curl函数
- ATV漏电
- Deprecated in iOS 5.0