GNU g++  v5.2.1
GNU Standard C++
stl_vector.h File Reference

This is an internal header file, included by other library headers. More...

Include dependency graph for stl_vector.h:
This graph shows which files directly or indirectly include this file:

Functions

namespace std _GLIBCXX_VISIBILITY (default)
 

Detailed Description

This is an internal header file, included by other library headers.

Do not attempt to use it directly. {vector}

Function Documentation

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.

Template Parameters
_TpType of element.
_AllocAllocator 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.

Parameters
__aAn allocator object.

Creates a vector with copies of an exemplar element.

Parameters
__nThe number of elements to initially create.
__valueAn element to copy.
__aAn allocator.

This constructor fills the vector with __n copies of __value.

Vector copy constructor.

Parameters
__xA 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.

Parameters
__firstAn input iterator.
__lastAn input iterator.
__aAn 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.

Parameters
__xA 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.

Parameters
__nNumber of elements to be assigned.
__valValue 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.

Parameters
__firstAn input iterator.
__lastAn 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.

Parameters
__new_sizeNumber of elements the vector should contain.
__xData 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.

Parameters
__nNumber of elements required.
Exceptions
std::length_errorIf 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.

Parameters
__nThe index of the element for which data should be accessed.
Returns
Read/write reference to data.

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.

Parameters
__nThe index of the element for which data should be accessed.
Returns
Read-only (constant) reference to data.

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.

Parameters
__nThe index of the element for which data should be accessed.
Returns
Read/write reference to data.
Exceptions
std::out_of_rangeIf __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.

Parameters
__nThe index of the element for which data should be accessed.
Returns
Read-only (constant) reference to data.
Exceptions
std::out_of_rangeIf __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.

Parameters
__xData 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.

Parameters
__positionAn iterator into the vector.
__xData to be inserted.
Returns
An iterator that points to the inserted data.

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.

Parameters
__positionAn iterator into the vector.
__nNumber of elements to be inserted.
__xData 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.

Parameters
__positionAn iterator into the vector.
__firstAn input iterator.
__lastAn 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.

Parameters
__positionIterator pointing to element to be erased.
Returns
An iterator pointing to the next element (or end()).

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.

Parameters
__firstIterator pointing to the first element to be erased.
__lastIterator pointing to one past the last element to be erased.
Returns
An iterator pointing to the element pointed to by __last prior to erasing (or end()).

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.

Parameters
__xA 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.

Parameters
__xA vector.
__yA vector of the same type as __x.
Returns
True iff the size and elements of the vectors are equal.

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.

Parameters
__xA vector.
__yA vector of the same type as __x.
Returns
True iff __x is lexicographically less than __y.

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().

Here is the call graph for this function: