C++ concepts: SequenceContainer - cppreference.com

##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# C++ concepts: SequenceContainer

From cppreference.com
< cpp‎ | concept

A `SequenceContainer` is a `Container` that stores objects of the same type in a linear arrangement.

### [edit] Requirements

### Legend
`X` | Container type
`T` | Element type
`a`, `b` | Objects of type `X`
`t` | Object of type `T`
`n` | Positive integer
`i`, `j` | `InputIterator`s denoting a valid range
`il` | std::initializer_list<T>
`args` | Parameter pack
`p`, `q` | const_iterators in `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)` | T `EmplaceConstructible` (only for std::vector) If the iterators are not `ForwardIterator`s, T must be `CopyInsertable` | 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` | T `CopyInsertable` (for std::vector and std::deque) T `MoveAssignable` and `MoveInsertable` |
a.insert(p,t) | iterator | Inserts a copy of `t` before `p` | T `CopyInsertable` (for std::vector and std::deque) T `CopyAssignable` or `MoveAssignable` |
a.insert(p,n,t) | iterator | Inserts `n` copies of `t` before `p` | T `CopyInsertable` and `CopyAssignable` |
a.insert(p,i,j) | iterator | Inserts copies of elements in `[i, j)` before `p` | T `EmplaceConstructible` (only for std::vector) If the iterators are not `ForwardIterator`s, T must be `MoveInsertable` and `MoveAssignable` `i` and `j` are not in `a` | 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` |  | All references are invalidated a.empty() == true
a.assign(i,j) | void | Replaces elements in a with a copy of `[i, j)` | T `EmplaceConstructible` (std::vector) If not `ForwardIterator` T `MoveInsertable` `i`, `j` not in `a` | 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` |

### [edit] Optional Operations

| This section is incomplete

### [edit] SequenceContainers in the standard library

array (since C++11) | static contiguous array (class template) [edit]
vector | dynamic contiguous array (class template) [edit]
deque | double-ended queue (class template) [edit]
forward_list (since C++11) | singly-linked list (class template) [edit]
list | doubly-linked list (class template) [edit]

#### [edit] Trade-offs / usage notes

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

Retrieved from "http://en.cppreference.com/mwiki/index.php?title=cpp/concept/SequenceContainer&oldid=66945"
Category:

- Todo without reason