C++ 概念: Container
来自cppreference.com
|
|
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
Container 是一种用来存放其它对象的对象,所含对象使用的内存也由它管理。
目录 |
[编辑] 要求
-
C容器类型 -
T元素类型 -
a、bC类型的对象
[编辑] 类型
| 名称 | 类型 | 备注 |
|---|---|---|
value_type |
T | Destructible
|
reference |
lvalue of T | |
const_reference |
const lvalue of T | |
iterator |
iterator pointing to T | ForwardIteratorconvertible to const_iterator
|
const_iterator |
const iterator pointing to T | ForwardIterator
|
difference_type |
signed integer | must be the same as iterator_traits中::difference_type for iterator and const_iterator
|
size_type |
unsigned integer | large enough to represent all positive values of difference_type
|
[编辑] 方法与操作符
| 表达式 | 返回类型 | 语义 | 条件 | 复杂度 | |
|---|---|---|---|---|---|
| C(); | C | 创建空容器 | 后置:u.empty() == true | 常数 | |
| C(a) | C | 创建 a 的副本 |
前置:T 必须 CopyInsertable后置:a == X(a) |
线性 | |
| a = b | C& | a 的所有元素都被销毁或移动赋值为 b 的元素 |
后置:a == b | 线性 | |
| (&a)->~C() | void | 销毁所有元素并释放内存 | 线性 | ||
| a.begin() | (const_)iterator | Iterator to the first element | 常数 | ||
| a.end() | (const_)iterator | Iterator to one passed the last element | 常数 | ||
| a.cbegin()(C++11 起) | const_iterator | const_cast<const C&>(a).begin() | 常数 | ||
| a.cend()(C++11 起) | const_iterator | const_cast<const C&>(a).end() | 常数 | ||
| a == b | convertible to bool | 使 C EqualityComparable |
Pre: T must be EqualityComparable |
线性 | |
| a != b | convertible to bool | !(a==b) | 线性 | ||
| a.swap(b) | void | 交换 a 和 b 的值 | 常数[1][2] | ||
| swap(a,b) | void | a.swap(b) | 常数[1] | ||
| a.size() | size_type | distance(a.begin(),a.end()) | 常数[2] | ||
| a.max_size() | size_type | b.size(),该 b 为可能存在的最大的 container | 常数[2] | ||
| a.empty() | convertible to bool | a.begin() == a.end() | 常数 | ||
| notes | |||||
[编辑] 容器数据争用
实现无需提供任何可重入性保证序列的修改 - 它是不是安全
push_back和兼读begin。然而,它是必需的以避免数据争相同的序列的不同的元素中所包含的对象的内容时,同时被修改(除了vector<bool>)。换句话说,为vector<int>大小大于1,x[1] = 5和*x.begin() = 10不会导致数据争.Original:
Implementations are not required to provide any reentrancy guarantee for sequence modifications - it is not safe to
push_back and read begin concurrently. However, it is required to avoid data races when the contents of the contained object in different elements of the same sequence are modified concurrently (except for vector<bool>). In other words, for a vector<int> with size greater than 1, x[1] = 5 and *x.begin() = 10 will not result in a data race.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
这些功能还必须考虑
const:begin,end,rbegin,rend,front,back,data,find,lower_bound,upper_bound,equal_range,at,而且,除了在AssociativeContainer和UnorderedAssociativeContainer,operator[]。同时调用这些功能将不会导致数据争用.Original:
These functions must also be considered
const: begin, end, rbegin, rend, front, back, data, find, lower_bound, upper_bound, equal_range, at, and, except in AssociativeContainer and UnorderedAssociativeContainer, operator[]. Calling any of these functions concurrently will not result in a data race.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[编辑] 其他概念
- C
- T