This is an internal header file, included by other library headers. More...
#include <bits/stl_iterator_base_funcs.h>
#include <bits/functexcept.h>
#include <bits/concept_check.h>
Functions | |
namespace std | _GLIBCXX_VISIBILITY (default) |
This is an internal header file, included by other library headers.
Do not attempt to use it directly. {vector}
namespace std _GLIBCXX_VISIBILITY | ( | default | ) |
See bits/stl_deque.h's _Deque_base for an explanation.
A standard container which offers fixed time access to individual elements in any order.
_Tp | Type of element. |
_Alloc | Allocator type, defaults to allocator<_Tp>. |
Meets the requirements of a container, a reversible container, and a sequence, including the optional sequence requirements with the exception of push_front
and pop_front
.
In some terminology a vector can be described as a dynamic C-style array, it offers fast and efficient access to individual elements in any order and saves the user from worrying about memory and size allocation. Subscripting ( [] ) access is also provided as with C-style arrays.
Creates a vector with no elements.
Creates a vector with no elements.
__a | An allocator object. |
Creates a vector with copies of an exemplar element.
__n | The number of elements to initially create. |
__value | An element to copy. |
__a | An allocator. |
This constructor fills the vector with __n copies of __value.
Vector copy constructor.
__x | A vector of identical element and allocator types. |
The newly-created vector uses a copy of the allocation object used by __x. All the elements of __x are copied, but any extra memory in __x (for fast expansion) will not be copied.
Builds a vector from a range.
__first | An input iterator. |
__last | An input iterator. |
__a | An allocator. |
Create a vector consisting of copies of the elements from [first,last).
If the iterators are forward, bidirectional, or random-access, then this will call the elements' copy constructor N times (where N is distance(first,last)) and do no memory reallocation. But if only input iterators are used, then this will do at most 2N calls to the copy constructor, and logN memory reallocations.
The dtor only erases the elements, and note that if the elements themselves are pointers, the pointed-to memory is not touched in any way. Managing the pointer is the user's responsibility.
Vector assignment operator.
__x | A vector of identical element and allocator types. |
All the elements of __x are copied, but any extra memory in __x (for fast expansion) will not be copied. Unlike the copy constructor, the allocator object is not copied.
Assigns a given value to a vector.
__n | Number of elements to be assigned. |
__val | Value to be assigned. |
This function fills a vector with __n copies of the given value. Note that the assignment completely changes the vector and that the resulting vector's size is the same as the number of elements assigned. Old data may be lost.
Assigns a range to a vector.
__first | An input iterator. |
__last | An input iterator. |
This function fills a vector with copies of the elements in the range [__first,__last).
Note that the assignment completely changes the vector and that the resulting vector's size is the same as the number of elements assigned. Old data may be lost.
Get a copy of the memory allocation object.
Returns a read/write iterator that points to the first element in the vector. Iteration is done in ordinary element order.
Returns a read-only (constant) iterator that points to the first element in the vector. Iteration is done in ordinary element order.
Returns a read/write iterator that points one past the last element in the vector. Iteration is done in ordinary element order.
Returns a read-only (constant) iterator that points one past the last element in the vector. Iteration is done in ordinary element order.
Returns a read/write reverse iterator that points to the last element in the vector. Iteration is done in reverse element order.
Returns a read-only (constant) reverse iterator that points to the last element in the vector. Iteration is done in reverse element order.
Returns a read/write reverse iterator that points to one before the first element in the vector. Iteration is done in reverse element order.
Returns a read-only (constant) reverse iterator that points to one before the first element in the vector. Iteration is done in reverse element order.
Returns the number of elements in the vector.
Returns the size() of the largest possible vector.
Resizes the vector to the specified number of elements.
__new_size | Number of elements the vector should contain. |
__x | Data with which new elements should be populated. |
This function will resize the vector to the specified number of elements. If the number is smaller than the vector's current size the vector is truncated, otherwise the vector is extended and new elements are populated with given data.
Returns the total number of elements that the vector can hold before needing to allocate more memory.
Returns true if the vector is empty. (Thus begin() would equal end().)
Attempt to preallocate enough memory for specified number of elements.
__n | Number of elements required. |
std::length_error | If n exceeds max_size() . |
This function attempts to reserve enough memory for the vector to hold the specified number of elements. If the number requested is more than max_size(), length_error is thrown.
The advantage of this function is that if optimal code is a necessity and the user can determine the number of elements that will be required, the user can reserve the memory in advance, and thus prevent a possible reallocation of memory and copying of vector data.
Subscript access to the data contained in the vector.
__n | The index of the element for which data should be accessed. |
This operator allows for easy, array-style, data access. Note that data access with this operator is unchecked and out_of_range lookups are not defined. (For checked lookups see at().)
Subscript access to the data contained in the vector.
__n | The index of the element for which data should be accessed. |
This operator allows for easy, array-style, data access. Note that data access with this operator is unchecked and out_of_range lookups are not defined. (For checked lookups see at().)
Safety check used only from at().
Provides access to the data contained in the vector.
__n | The index of the element for which data should be accessed. |
std::out_of_range | If __n is an invalid index. |
This function provides for safer data access. The parameter is first checked that it is in the range of the vector. The function throws out_of_range if the check fails.
Provides access to the data contained in the vector.
__n | The index of the element for which data should be accessed. |
std::out_of_range | If __n is an invalid index. |
This function provides for safer data access. The parameter is first checked that it is in the range of the vector. The function throws out_of_range if the check fails.
Returns a read/write reference to the data at the first element of the vector.
Returns a read-only (constant) reference to the data at the first element of the vector.
Returns a read/write reference to the data at the last element of the vector.
Returns a read-only (constant) reference to the data at the last element of the vector.
Returns a pointer such that [data(), data() + size()) is a valid range. For a non-empty vector, data() == &front().
Add data to the end of the vector.
__x | Data to be added. |
This is a typical stack operation. The function creates an element at the end of the vector and assigns the given data to it. Due to the nature of a vector this operation can be done in constant time if the vector has preallocated space available.
Removes last element.
This is a typical stack operation. It shrinks the vector by one.
Note that no data is returned, and if the last element's data is needed, it should be retrieved before pop_back() is called.
Inserts given value into vector before specified iterator.
__position | An iterator into the vector. |
__x | Data to be inserted. |
This function will insert a copy of the given value before the specified location. Note that this kind of operation could be expensive for a vector and if it is frequently used the user should consider using std::list.
Inserts a number of copies of given data into the vector.
__position | An iterator into the vector. |
__n | Number of elements to be inserted. |
__x | Data to be inserted. |
This function will insert a specified number of copies of the given data before the location specified by position.
Note that this kind of operation could be expensive for a vector and if it is frequently used the user should consider using std::list.
Inserts a range into the vector.
__position | An iterator into the vector. |
__first | An input iterator. |
__last | An input iterator. |
This function will insert copies of the data in the range [__first,__last) into the vector before the location specified by pos.
Note that this kind of operation could be expensive for a vector and if it is frequently used the user should consider using std::list.
Remove element at given position.
__position | Iterator pointing to element to be erased. |
This function will erase the element at the given position and thus shorten the vector by one.
Note This operation could be expensive and if it is frequently used the user should consider using std::list. The user is also cautioned that this function only erases the element, and that if the element is itself a pointer, the pointed-to memory is not touched in any way. Managing the pointer is the user's responsibility.
Remove a range of elements.
__first | Iterator pointing to the first element to be erased. |
__last | Iterator pointing to one past the last element to be erased. |
This function will erase the elements in the range [__first,__last) and shorten the vector accordingly.
Note This operation could be expensive and if it is frequently used the user should consider using std::list. The user is also cautioned that this function only erases the elements, and that if the elements themselves are pointers, the pointed-to memory is not touched in any way. Managing the pointer is the user's responsibility.
Swaps data with another vector.
__x | A vector of the same element and allocator types. |
This exchanges the elements between two vectors in constant time. (Three pointers, so it should be quite fast.) Note that the global std::swap() function is specialized such that std::swap(v1,v2) will feed to this function.
Erases all the elements. Note that this function only erases the elements, and that if the elements themselves are pointers, the pointed-to memory is not touched in any way. Managing the pointer is the user's responsibility.
Memory expansion handler. Uses the member allocation function to obtain n bytes of memory, and then copies [first,last) into it.
Vector equality comparison.
__x | A vector. |
__y | A vector of the same type as __x. |
This is an equivalence relation. It is linear in the size of the vectors. Vectors are considered equivalent if their sizes are equal, and if corresponding elements compare equal.
Vector ordering relation.
__x | A vector. |
__y | A vector of the same type as __x. |
This is a total ordering relation. It is linear in the size of the vectors. The elements must be comparable with <
.
See std::lexicographical_compare() for how the determination is made.
Based on operator==
Based on operator<
Based on operator<
Based on operator<
See std::vector::swap().
References __catch, __glibcxx_class_requires, __glibcxx_class_requires2, __throw_exception_again, __try, __gnu_parallel::max(), std::__exception_ptr::operator!=(), std::__exception_ptr::operator==(), __gnu_debug::operator>(), __gnu_debug::operator>=(), and std::__exception_ptr::swap().