| Version: 3.0.1

- Main Page
- Related Pages
- Categories
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Types | Public Member Functions | List of all members
wxVector< T > Class Template Reference
Containers

`#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_type * | pointer
typedef value_type * | iterator
typedef const value_type * | const_iterator
typedef value_type & | reference

## Public Member Functions

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

## Member Typedef Documentation

template<typename T >

typedef const value_type* wxVector< T >::const_iterator

template<typename T >

typedef size_t wxVector< T >::difference_type

template<typename T >

typedef value_type* wxVector< T >::iterator

template<typename T >

typedef value_type* wxVector< T >::pointer

template<typename T >

typedef value_type& wxVector< T >::reference

template<typename T >

typedef size_t wxVector< T >::size_type

template<typename T >

typedef T wxVector< T >::value_type

## Constructor & Destructor Documentation

template<typename T >

wxVector< T >::wxVector | ( |  | ) |

Constructor.

template<typename T >

wxVector< T >::wxVector | ( | size_type | size | ) |

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

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.

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 not including, last to the vector.

Since
  2.9.5

template<typename T >

wxVector< T >::wxVector | ( | const wxVector< T > & | c | ) |

Copy constructor.

template<typename T >

wxVector< T >::~wxVector | ( |  | ) |

Destructor.

## Member Function Documentation

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

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

template<typename T >

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

Returns item at position idx.

template<typename T >

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

Returns item at position idx.

template<typename T >

const value_type& wxVector< T >::back | ( |  | ) | const

Return the last item.

template<typename T >

value_type& wxVector< T >::back | ( |  | ) |

Return the last item.

template<typename T >

const_iterator wxVector< T >::begin | ( |  | ) | const

Return iterator to beginning of the vector.

template<typename T >

iterator wxVector< T >::begin | ( |  | ) |

Return iterator to beginning of the vector.

template<typename T >

size_type wxVector< T >::capacity | ( |  | ) | const

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

See Also
  reserve()

template<typename T >

void wxVector< T >::clear | ( |  | ) |

Clears the vector.

template<typename T >

bool wxVector< T >::empty | ( |  | ) | const

Returns true if the vector is empty.

template<typename T >

const_iterator wxVector< T >::end | ( |  | ) | const

Returns iterator to the end of the vector.

template<typename T >

iterator wxVector< T >::end | ( |  | ) |

Returns iterator to the end of the vector.

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.

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.

template<typename T >

const value_type& wxVector< T >::front | ( |  | ) | const

Returns the first item.

template<typename T >

value_type& wxVector< T >::front | ( |  | ) |

Returns the first item.

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.

template<typename T >

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

Assignment operator.

template<typename T >

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

Returns item at position idx.

template<typename T >

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

Returns item at position idx.

template<typename T >

void wxVector< T >::pop_back | ( |  | ) |

Removes the last item.

template<typename T >

void wxVector< T >::push_back | ( | const value_type & | v | ) |

Adds an item to the end of the vector.

template<typename T >

reverse_iterator wxVector< T >::rbegin | ( |  | ) |

Return reverse iterator to end of the vector.

template<typename T >

reverse_iterator wxVector< T >::rend | ( |  | ) |

Return reverse iterator to beginning of the vector.

template<typename T >

void wxVector< T >::reserve | ( | size_type | n | ) |

Reserves memory for at least n items.

See Also
  capacity()

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.

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.

template<typename T >

size_type wxVector< T >::size | ( |  | ) | const

Returns the size of the vector.

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