C++ 概念: SequenceContainer
来自cppreference.com
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
甲
SequenceContainer
是一个存储在一个线性排列的相同类型的对象的Container
.原文:
A
SequenceContainer
is a Container
that stores objects of the same type in a linear arrangement.目录 |
[编辑] 要求
| |
X
|
容器类型
|
T
|
元素的类型
|
a , b
|
对象的类型
X |
t
|
对象的类型
T |
n
|
正整数
|
i , j
|
的有效范围
InputIterator s表示原文: InputIterator s denoting a valid range |
il
|
std::initializer_list<T> |
args
|
参数组
|
p , q
|
const_iterators
a |
expression | return type | effects | precondition | postcondition |
---|---|---|---|---|
X(n,t) | Constructs a SequenceContainer containing n copies of t |
T CopyInsertable |
std::distance(begin(),end()) == n | |
X(i,j) | Constructs a SequenceContainer equivalent to the range [i,j)
|
std::distance(begin(),end()) == std::distance(i,j) | ||
X(il) | X(il.begin(),il.end) | |||
a = il | X& | Assigns the range represented by il into a
|
T CopyInsertable and CopyAssignable
|
Existing elements of a are destroyed or assigned to
|
a.emplace(p,args) | iterator | Insert an object constructed with std::forward<Args>(args) before p
|
|
|
a.emplace(p,t) | iterator | Inserts a copy of t before i
|
|
|
a.insert(p,n,t) | iterator | Inserts n copies of t before i
|
T CopyInsertable and CopyAssignable
|
|
a.insert(p,i,j) | iterator | Inserts copies of elements in [i, j) before p
|
|
Each iterator in [i,j) is dereferenced once
|
a.insert(p, il) | iterator | a.insert(p,il.begin(),il.end()) | ||
a.erase(q) | iterator | Erases the element pointed to by q | (std :: deque的,std :: vector的) T MoveAssignable
|
|
a.erase(p,q) | iterator | Erases elements in [p,q) |
(std :: deque的,std :: vector的) T MoveAssignable |
|
a.clear() | void | Destroys all elements in a |
| |
a.assign(i,j) | void | Replaces elements in a with a copy of [i, j)
|
|
Each iterator in [i,j) is dereferenced once
|
a.assign(il) | void | a.assign(il.begin(),il.end()) | ||
a.assign(n,t) | void | Replaces elements in a with n copies of t
|
T CopyInsertable and CopyAssignable
|
[编辑] 可选操作
本章尚未完成 |
[编辑] 标准库的SequenceContainers中
(C++11 起) |
静态连续的数组 (类模板) |
动态连续的数组 (类模板) | |
双端队列 (类模板) | |
(C++11 起) |
单向链表 (类模板) |
双向链表 (类模板) |
[编辑] 权衡/使用说明
std::array | 快速访问,但固定数量的元素
原文: Fast access but fixed number of elements |
std::vector | 快速访问,但大多是低效率的插入/缺失
原文: Fast access but mostly inefficient insertions/deletions |
std::list std::forward_list |
高效的插入/缺失的序列在中间
原文: Efficient insertion/deletion in the middle of the sequence |
std::deque | 在开始和结束时的序列的高效的插入/缺失
原文: Efficient insertion/deletion at the beginning and at the end of the sequence |