Version: 3.2.5
wxVector< T > Class Template Reference

#include <wx/vector.h>

Detailed Description

template<typename T>
class wxVector< T >

wxVector<T> is a template class which implements most of the std::vector class and can be used like it.

If wxWidgets is compiled in STL mode, wxVector will just be a typedef to std::vector. Just like for std::vector, objects stored in wxVector<T> need to be assignable but don't have to be "default constructible".

Please refer to the STL documentation for further information.

Library:  None; this class implementation is entirely header-based.
Category:  Containers
See also
Container Classes, wxList<T>, wxArray<T>, wxVectorSort<T>

Public Types

typedef size_t size_type
 
typedef size_t difference_type
 
typedef T value_type
 
typedef value_typepointer
 
typedef value_typeiterator
 
typedef const value_typeconst_iterator
 
typedef value_typereference
 

Public Member Functions

 wxVector ()
 Constructor. More...
 
 wxVector (size_type size)
 Constructor initializing the vector with the given number of default-constructed objects. More...
 
 wxVector (size_type size, const value_type &value)
 Constructor initializing the vector with the given number of copies of the given object. More...
 
template<class InputIterator >
 wxVector (InputIterator first, InputIterator last)
 Constructor initializing the vector with the elements in the given range. More...
 
 wxVector (const wxVector< T > &c)
 Copy constructor. More...
 
 ~wxVector ()
 Destructor. More...
 
void assign (size_type n, const value_type &v)
 Resizes the vector to n and assigns v to all elements. More...
 
template<class InputIterator >
void assign (InputIterator first, InputIterator last)
 Assigns the elements in the given range to the vector. More...
 
const value_typeat (size_type idx) const
 Returns item at position idx. More...
 
value_typeat (size_type idx)
 Returns item at position idx. More...
 
const value_typeback () const
 Return the last item. More...
 
value_typeback ()
 Return the last item. More...
 
const_iterator begin () const
 Return iterator to beginning of the vector. More...
 
iterator begin ()
 Return iterator to beginning of the vector. More...
 
reverse_iterator rbegin ()
 Return reverse iterator to end of the vector. More...
 
reverse_iterator rend ()
 Return reverse iterator to beginning of the vector. More...
 
size_type capacity () const
 Returns vector's current capacity, i.e. how much memory is allocated. More...
 
void clear ()
 Clears the vector. More...
 
bool empty () const
 Returns true if the vector is empty. More...
 
const_iterator end () const
 Returns iterator to the end of the vector. More...
 
iterator end ()
 Returns iterator to the end of the vector. More...
 
iterator erase (iterator it)
 Erase item pointed to by iterator it. More...
 
iterator erase (iterator first, iterator last)
 Erase items in the range first to last (last is not erased). More...
 
const value_typefront () const
 Returns the first item. More...
 
value_typefront ()
 Returns the first item. More...
 
iterator insert (iterator it, const value_type &v=value_type())
 Insert item v at given position it. More...
 
iterator insert (iterator it, size_type count, const value_type &v)
 Insert the given number of copies of v at the given position. More...
 
wxVectoroperator= (const wxVector &vb)
 Assignment operator. More...
 
wxVectoroperator== (const wxVector &vb) const
 Equality operator. More...
 
wxVectoroperator!= (const wxVector &vb) const
 Inequality operator. More...
 
const value_typeoperator[] (size_type idx) const
 Returns item at position idx. More...
 
value_typeoperator[] (size_type idx)
 Returns item at position idx. More...
 
void pop_back ()
 Removes the last item. More...
 
void push_back (const value_type &v)
 Adds an item to the end of the vector. More...
 
void reserve (size_type n)
 Reserves memory for at least n items. More...
 
void shrink_to_fit ()
 Free unused memory allocated by the vector. More...
 
size_type size () const
 Returns the size of the vector. More...
 
void swap (wxVector &v)
 Efficiently exchanges contents of this vector with another one. More...
 
void resize (size_type n)
 Makes the vector of size n. More...
 
void resize (size_type n, const value_type &v)
 Makes the vector of size n. More...
 

Member Typedef Documentation

◆ const_iterator

template<typename T >
typedef const value_type* wxVector< T >::const_iterator

◆ difference_type

template<typename T >
typedef size_t wxVector< T >::difference_type

◆ iterator

template<typename T >
typedef value_type* wxVector< T >::iterator

◆ pointer

template<typename T >
typedef value_type* wxVector< T >::pointer

◆ reference

template<typename T >
typedef value_type& wxVector< T >::reference

◆ size_type

template<typename T >
typedef size_t wxVector< T >::size_type

◆ value_type

template<typename T >
typedef T wxVector< T >::value_type

Constructor & Destructor Documentation

◆ wxVector() [1/5]

template<typename T >
wxVector< T >::wxVector ( )

Constructor.

◆ wxVector() [2/5]

template<typename T >
wxVector< T >::wxVector ( size_type  size)

Constructor initializing the vector with the given number of default-constructed objects.

◆ wxVector() [3/5]

template<typename T >
wxVector< T >::wxVector ( size_type  size,
const value_type value 
)

Constructor initializing the vector with the given number of copies of the given object.

◆ wxVector() [4/5]

template<typename T >
template<class InputIterator >
wxVector< T >::wxVector ( InputIterator  first,
InputIterator  last 
)

Constructor initializing the vector with the elements in the given range.

The InputIterator template parameter must be an input iterator type. This constructor adds all elements from first until, not including, last to the vector.

Since
2.9.5

◆ wxVector() [5/5]

template<typename T >
wxVector< T >::wxVector ( const wxVector< T > &  c)

Copy constructor.

◆ ~wxVector()

template<typename T >
wxVector< T >::~wxVector ( )

Destructor.

Member Function Documentation

◆ assign() [1/2]

template<typename T >
template<class InputIterator >
void wxVector< T >::assign ( InputIterator  first,
InputIterator  last 
)

Assigns the elements in the given range to the vector.

The InputIterator template parameter must be an input iterator type. This method clears the vector and then adds all elements from first until, not not including, last to it.

Since
2.9.5

◆ assign() [2/2]

template<typename T >
void wxVector< T >::assign ( size_type  n,
const value_type v 
)

Resizes the vector to n and assigns v to all elements.

See also
resize()
Since
2.9.5

◆ at() [1/2]

template<typename T >
value_type& wxVector< T >::at ( size_type  idx)

Returns item at position idx.

◆ at() [2/2]

template<typename T >
const value_type& wxVector< T >::at ( size_type  idx) const

Returns item at position idx.

◆ back() [1/2]

template<typename T >
value_type& wxVector< T >::back ( )

Return the last item.

◆ back() [2/2]

template<typename T >
const value_type& wxVector< T >::back ( ) const

Return the last item.

◆ begin() [1/2]

template<typename T >
iterator wxVector< T >::begin ( )

Return iterator to beginning of the vector.

◆ begin() [2/2]

template<typename T >
const_iterator wxVector< T >::begin ( ) const

Return iterator to beginning of the vector.

◆ capacity()

template<typename T >
size_type wxVector< T >::capacity ( ) const

Returns vector's current capacity, i.e. how much memory is allocated.

See also
reserve()

◆ clear()

template<typename T >
void wxVector< T >::clear ( )

Clears the vector.

◆ empty()

template<typename T >
bool wxVector< T >::empty ( ) const

Returns true if the vector is empty.

◆ end() [1/2]

template<typename T >
iterator wxVector< T >::end ( )

Returns iterator to the end of the vector.

◆ end() [2/2]

template<typename T >
const_iterator wxVector< T >::end ( ) const

Returns iterator to the end of the vector.

◆ erase() [1/2]

template<typename T >
iterator wxVector< T >::erase ( iterator  first,
iterator  last 
)

Erase items in the range first to last (last is not erased).

Returns
Iterator pointing to the item immediately after the erased range.

◆ erase() [2/2]

template<typename T >
iterator wxVector< T >::erase ( iterator  it)

Erase item pointed to by iterator it.

Returns
Iterator pointing to the item immediately after the erased one.

◆ front() [1/2]

template<typename T >
value_type& wxVector< T >::front ( )

Returns the first item.

◆ front() [2/2]

template<typename T >
const value_type& wxVector< T >::front ( ) const

Returns the first item.

◆ insert() [1/2]

template<typename T >
iterator wxVector< T >::insert ( iterator  it,
const value_type v = value_type() 
)

Insert item v at given position it.

Returns
Iterator for the inserted item.

◆ insert() [2/2]

template<typename T >
iterator wxVector< T >::insert ( iterator  it,
size_type  count,
const value_type v 
)

Insert the given number of copies of v at the given position.

Returns
Iterator for the first inserted item.
Since
3.1.1

◆ operator!=()

template<typename T >
wxVector& wxVector< T >::operator!= ( const wxVector< T > &  vb) const

Inequality operator.

Since
3.1.1

◆ operator=()

template<typename T >
wxVector& wxVector< T >::operator= ( const wxVector< T > &  vb)

Assignment operator.

◆ operator==()

template<typename T >
wxVector& wxVector< T >::operator== ( const wxVector< T > &  vb) const

Equality operator.

Since
3.1.1

◆ operator[]() [1/2]

template<typename T >
value_type& wxVector< T >::operator[] ( size_type  idx)

Returns item at position idx.

◆ operator[]() [2/2]

template<typename T >
const value_type& wxVector< T >::operator[] ( size_type  idx) const

Returns item at position idx.

◆ pop_back()

template<typename T >
void wxVector< T >::pop_back ( )

Removes the last item.

◆ push_back()

template<typename T >
void wxVector< T >::push_back ( const value_type v)

Adds an item to the end of the vector.

◆ rbegin()

template<typename T >
reverse_iterator wxVector< T >::rbegin ( )

Return reverse iterator to end of the vector.

◆ rend()

template<typename T >
reverse_iterator wxVector< T >::rend ( )

Return reverse iterator to beginning of the vector.

◆ reserve()

template<typename T >
void wxVector< T >::reserve ( size_type  n)

Reserves memory for at least n items.

See also
capacity()

◆ resize() [1/2]

template<typename T >
void wxVector< T >::resize ( size_type  n)

Makes the vector of size n.

If n is less than the current size(), the elements at the end of the vector are erased. If it is greater, then the vector is completed with either the copies of the given object v or value_type() objects until it becomes of size n.

◆ resize() [2/2]

template<typename T >
void wxVector< T >::resize ( size_type  n,
const value_type v 
)

Makes the vector of size n.

If n is less than the current size(), the elements at the end of the vector are erased. If it is greater, then the vector is completed with either the copies of the given object v or value_type() objects until it becomes of size n.

◆ shrink_to_fit()

template<typename T >
void wxVector< T >::shrink_to_fit ( )

Free unused memory allocated by the vector.

Reduces the memory used by the vector to the bare minimum required to hold its current number of elements, possibly 0.

After calling this method, capacity() returns the same as size().

Since
3.1.1

◆ size()

template<typename T >
size_type wxVector< T >::size ( ) const

Returns the size of the vector.

◆ swap()

template<typename T >
void wxVector< T >::swap ( wxVector< T > &  v)

Efficiently exchanges contents of this vector with another one.

After the execution of this function the contents of this vector is equal to the original contents of v and the contents of v becomes the original contents of this vector without copying the data.

Since
2.9.1