template <class InputIterator> vector(InputIterator, InputIterator) [1]Sequence Creates a vector with a copy of a range. ~vector() Container The destructor. vector& operator=(const vector&) Container The assignment operator void reserve(size_t) vector See below. reference front() Sequence Returns the first element. const_reference front() const Sequence Returns the first element. reference back() Back Insertion Sequence Returns the last element. const_reference back() const Back Insertion Sequence Returns the last element. void push_back(const T&) Back Insertion Sequence Inserts a new element at the end. void pop_back() Back Insertion Sequence Removes the last element. void swap(vector&) Container Swaps the contents of two vectors.
iterator insert(iterator pos, const T& x)Sequence Inserts x before pos.
template <class InputIterator> void insert(iterator pos, InputIterator f, InputIterator l) [1]Sequence Inserts the range [first, last) before pos.
void insert(iterator pos, size_type n, const T& x)Sequence Inserts n copies of x before pos. iterator erase(iterator pos) Sequence Erases the element at position pos. iterator erase(iterator first, iterator last) Sequence Erases the range [first, last) void clear() Sequence Erases all of the elements. void resize(n, t = T()) Sequence Inserts or erases elements at the end such that the size becomes n.
bool operator==(const vector&, const vector&)Forward Container Tests two vectors for equality. This is a global function, not a member function.
bool operator<(const vector&, const vector&)Forward Container Lexicographical comparison. This is a global function, not a member function.
[1] This member function relies on member template functions, which at present (early 1998) are not supported by all compilers. If your compiler supports member templates, you can call this function with any type of input iterator. If your compiler does not yet support member templates, though, then the arguments must be of type const value_type*.
[2] Memory will be reallocated automatically if more than capacity() - size() elements are inserted into the vector. Reallocation does not change size(), nor does it change the values of any elements of the vector. It does, however, increase capacity(), and it invalidates [5] any iterators that point into the vector.
[3] When it is necessary to increase capacity(), vector usually increases it by a factor of two. It is crucial that the amount of growth is proportional to the current capacity(), rather than a fixed constant: in the former case inserting a series of elements into a vector is a linear time operation, and in the latter case it is quadratic.
[4] Reserve() causes a reallocation manually. The main reason for using reserve() is efficiency: if you know the capacity to which your vector must eventually grow, then it is usually more efficient to allocate that memory all at once rather than relying on the automatic reallocation scheme. The other reason for using reserve() is so that you can control the invalidation of iterators. [5]
[5] A vector's iterators are invalidated when its memory is reallocated. Additionally, inserting or deleting an element in the middle of a vector invalidates all iterators that point to elements following the insertion or deletion point. It follows that you can prevent a vector's iterators from being invalidated if you use reserve() to preallocate as much memory as the vector will ever use, and if all insertions and deletions are at the vector's end.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4