vector
|
 |
A sequential container that is
similar to a regular C array, except the vector can expand to accommodate new
elements.
Library
Standards<ToolKit>
Declaration
#include <vector>
template< class T, class Allocator >
class vector
Interface
Constructor
vector()
Constructs an empty
vector.
Constructor
explicit
vector( allocator_type& alloc )
Constructs an empty
vector, using alloc to manage storage.
Constructor
explicit
vector( size_type n ,
const T& value ,
const Allocator& alloc )
Constructs a vector that
contains n copies of value
(default T() ), using alloc
(default Allocator() ) to manage storage.
Constructor
vector(
iterator first ,
iterator last ,
const Allocator& alloc )
Constructs a vector that
contains copies of all the elements in the range [
first , last
) , using alloc
(default Allocator() ) to manage storage.
Constructor
vector(
const vector< T, Allocator >& other )
Constructs a vector that
is a copy of other .
Destructor
~vector()
Destroys the vector and
erases all of its items.
=
vector<T>&
operator=( const vector< T >& x )
Replaces the contents of
vector with those of x .
[]
T&
operator []( int index )
Returns a reference to
the element at index .
[]
const
T& operator []( int index )
const
Returns a constant
reference to the element at index .
assign
void
assign( const_iterator first, const_iterator last )
Erases all elements, then
inserts the elements in the range [ first , last
).
assign
void
assign( size_type n ,
const T& value )
Erases all elements, then
inserts n copies of value
(default T() ).
at
T&
at( size_type index )
Returns a reference to
the element at index .
at
const
T& at( size_type index )
const
Returns a constant
reference to the element at index .
back
T&
back()
Returns a reference to
the last element in the vector.
back
const
T& back() const
Returns a constant
reference to the last element in the vector.
begin
iterator
begin()
Returns an iterator
positioned at the first item in the vector.
begin
const_iterator
begin() const
Returns a constant
iterator positioned at the first item in the vector.
capacity
size_type
capacity() const
Returns the number of
elements the vector can contain without allocating more memory.
clear
void
clear()
Erases all of the
elements in the vector.
empty
bool
empty() const
Returns true
if the vector contains no entries.
end
iterator
end()
Returns an iterator
positioned immediately after the last item in the vector.
end
const_iterator
end() const
Returns a constant
iterator positioned immediately after the last item in the vector.
erase
void
erase( iterator pos )
Erases the element at pos
.
erase
void
erase( iterator first ,
iterator last )
Erases elements in the
range [ first ,
last ) .
front
T&
front()
Returns a reference to
the first element in the vector.
front
const
T& front() const
Returns a constant
reference to the first element in the vector.
get_allocator
Allocator
get_allocator() const
Returns a copy of the
allocator the vector is using to manage storage.
insert
iterator
insert( iterator pos ,
const T& value )
Inserts value
(default T() ) at pos
and returns an iterator pointing to the new element's position.
insert
void
insert( iterator pos ,
size_type n ,
const T& value )
Inserts n
copies of value at pos .
insert
void
insert( iterator pos ,
const_iterator first ,
const_iterator last )
Inserts copies of the
elements in the range [ first
, last )
at pos .
max_size
size_type
max_size() const
Returns the maximum
number of entries the vector can contain.
push_back
void
push_back( const T& value )
Adds value
at the end of the vector.
pop_back
void
pop_back()
Erases the last element
in the vector.
rbegin
reverse_iterator
rbegin()
Returns a reverse
iterator positioned at the last item in the vector.
rbegin
const_reverse_iterator
rbegin() const
Returns a constant
reverse iterator positioned at the last item in the vector.
rend
reverse_iterator
rend()
Returns a reverse
iterator positioned immediately before the first item in the vector.
rend
const_reverse_iterator
rend() const
Returns a constant
reverse iterator positioned immediately before the first item in the vector.
reserve
void
reserve( size_type n )
Preallocates enough space
to hold up to n elements. This operation does not
change the value returned by size() .
resize
void
resize( size_type n ,
T value )
Adjusts the vector to
hold n elements, using value
(default T() ) to expand the vector if
necessary.
size
size_type
size() const
Returns the number of
entries the vector contains.
swap
void
swap( vector< T, Allocator >& other
)
Exchanges the contents of
the vector and other .
Non-Member Functions
==
bool
operator==( const vector< T, Allocator >& x
, const vector< T, Allocator
>& y )
Returns true
if x contains the same elements in the same order
as y .
<
bool
operator<( const vector< T, Allocator >& x
, const vector< T, Allocator
>& y )
Returns true
if x is lexicographically less than y
.
swap
void
swap( const vector< T, Allocator >& x
, const vector< T, Allocator
>& y )
Exchanges the contents of
x and y .
Copyright©1994-2026 Recursion Software LLC
All Rights Reserved - For use by licensed users only.