]>
git.saurik.com Git - wxWidgets.git/blob - interface/wx/vector.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxVector<T>
4 // Author: wxWidgets team
5 // Licence: wxWindows licence
6 /////////////////////////////////////////////////////////////////////////////
10 wxVector<T> is a template class which implements most of the @c std::vector
11 class and can be used like it.
13 If wxWidgets is compiled in STL mode, wxVector will just be a typedef to
14 @c std::vector. Just like for @c std::vector, objects stored in wxVector<T>
15 need to be @e assignable but don't have to be @e "default constructible".
17 Please refer to the STL documentation for further information.
22 @see @ref overview_container, wxList<T>, wxArray<T>, wxVectorSort<T>
28 typedef size_t size_type
;
29 typedef size_t difference_type
;
31 typedef value_type
* pointer
;
32 typedef value_type
* iterator
;
33 typedef const value_type
* const_iterator
;
34 typedef value_type
& reference
;
42 Constructor initializing the vector with the given number of
43 default-constructed objects.
45 wxVector(size_type size
);
48 Constructor initializing the vector with the given number of
49 copies of the given object.
51 wxVector(size_type size
, const value_type
& value
);
54 Constructor initializing the vector with the elements in the given
57 The @a InputIterator template parameter must be an input iterator type.
58 This constructor adds all elements from @a first until, not not
59 including, @a last to the vector.
63 template <class InputIterator
>
64 wxVector(InputIterator first
, InputIterator last
);
69 wxVector(const wxVector
<T
>& c
);
77 Resizes the vector to @a n and assigns @a v to all elements.
83 void assign(size_type n
, const value_type
& v
);
86 Assigns the elements in the given range to the vector.
88 The @a InputIterator template parameter must be an input iterator type.
89 This method clears the vector and then adds all elements from @a first
90 until, not not including, @a last to it.
94 template <class InputIterator
>
95 void assign(InputIterator first
, InputIterator last
);
98 Returns item at position @a idx.
100 const value_type
& at(size_type idx
) const;
103 Returns item at position @a idx.
105 value_type
& at(size_type idx
);
108 Return the last item.
110 const value_type
& back() const;
113 Return the last item.
118 Return iterator to beginning of the vector.
120 const_iterator
begin() const;
123 Return iterator to beginning of the vector.
128 Return reverse iterator to end of the vector.
130 reverse_iterator
rbegin();
133 Return reverse iterator to beginning of the vector.
135 reverse_iterator
rend();
139 Returns vector's current capacity, i.e.\ how much memory is allocated.
143 size_type
capacity() const;
151 Returns @true if the vector is empty.
156 Returns iterator to the end of the vector.
158 const_iterator
end() const;
161 Returns iterator to the end of the vector.
166 Erase item pointed to by iterator @a it.
168 @return Iterator pointing to the item immediately after the erased one.
170 iterator
erase(iterator it
);
173 Erase items in the range @a first to @a last (@a last is not erased).
175 @return Iterator pointing to the item immediately after the erased
178 iterator
erase(iterator first
, iterator last
);
181 Returns the first item.
183 const value_type
& front() const;
186 Returns the first item.
191 Insert item @a v at given position @a it.
193 @return Iterator for the inserted item.
195 iterator
insert(iterator it
, const value_type
& v
= value_type());
200 wxVector
& operator=(const wxVector
& vb
);
203 Returns item at position @a idx.
205 const value_type
& operator[](size_type idx
) const;
208 Returns item at position @a idx.
210 value_type
& operator[](size_type idx
);
213 Removes the last item.
218 Adds an item to the end of the vector.
220 void push_back(const value_type
& v
);
223 Reserves memory for at least @a n items.
227 void reserve(size_type n
);
230 Makes the vector of size @a n.
232 If @a n is less than the current size(), the elements at the end of the
233 vector are erased. If it is greater, then the vector is completed with
234 either the copies of the given object @a v or @c value_type() objects
235 until it becomes of size @a n.
238 void resize(size_type n
);
239 void resize(size_type n
, const value_type
& v
);
243 Returns the size of the vector.
245 size_type
size() const;
248 Efficiently exchanges contents of this vector with another one.
250 After the execution of this function the contents of this vector is
251 equal to the original contents of @a v and the contents of @a v becomes
252 the original contents of this vector without copying the data.
256 void swap(wxVector
& v
);
261 Sort the contents of a @c wxVector<T>. In a STL build this function will
262 be defined as a thin wrapper around std::sort. To be sortable the
263 contained type must support the less-than operator.
266 wxVector<SomeClass> v;
267 ... // items are added to the vector v...
274 void wxVectorSort(wxVector
<T
>& v
);