Container
C++概念:容器
阿Container
是一个用于存储其他对象并负责管理其包含的对象所使用的内存的对象。
所需
C
集装箱类型;
T
元素类型;
a
,,,b
类型对象C
...
类型
name | type | notes |
---|---|---|
value_type | T | Eraseable |
reference | T& | |
const_reference | const 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 |
方法和操作
expression | return type | semantics | conditions | complexity |
---|---|---|---|---|
C() | C | creates an empty container | Post: C().empty() == true | Constant |
C(a) | C | creates a copy of a | Pre: T must be CopyInsertablePost: a == C(a) | Linear |
a = b | C& | destroys or move-assigns all elements of a from elements of b | Post: a == b | Linear |
(&a)->~C() | void | destroys all elements of a and frees all memory | | Linear |
a.begin() | (const_)iterator | Iterator to the first element of a | | Constant |
a.end() | (const_)iterator | Iterator to one past the last element of a | | Constant |
a.cbegin()(since C++11) | const_iterator | const_cast<const C&>(a).begin() | | Constant |
a.cend()(since C++11) | const_iterator | const_cast<const C&>(a).end() | | Constant |
a == b | convertible to bool | std::equal(a.begin(), a.end(), b.begin(), b.end())(since C++14) | Pre: T must be EqualityComparable | Constant1 if a.size() != b.size(), linear otherwise |
a != b | convertible to bool | !(a == b) | | Linear |
a.swap(b) | void | exchanges the values of a and b | | Constant2 |
swap(a, b) | void | a.swap(b) | | Constant2 |
a.size() | size_type | distance(a.begin(), a.end()) | | Constant3 |
a.max_size() | size_type | b.size() where b is the largest possible container | | Constant3 |
a.empty() | convertible to bool | a.begin() == a.end() | | Constant |
注记
对于STD总是线性的::正向[医]列表%28自C++11%29线性表示STD::数组%28,直到C++11%29不严格恒定
- 总是线性的
std::forward_list
- %28自C++11%29线性
std::array
- %28直到C++11%29没有严格不变
Given. i and j, objects of a container's iterator type, in the expressions i == j, i != j, i < j, i <= j, i >= j, i > j, i - j, either or both may be replaced by an object of the container's const_iterator type referring to the same element with no change in semantics. | (since C++14) |
---|
- i和j,容器%27s的对象iterator类型,在表达式中i == j,,,i != j,,,i < j,,,i <= j,,,i >= j,,,i > j,,,i - j,可以用容器%27s的对象替换其中之一或两者。const_iterator类型引用相同的元素,语义不变。 %28自C++14%29容器数据竞赛见集装箱螺纹安全...其他概念丙
DefaultConstructible
CopyConstructible
EqualityComparable
Swappable
T型
CopyInsertable
EqualityComparable
Destructible
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。