]>
git.saurik.com Git - wxWidgets.git/blob - interface/wx/vector.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxVector<T>
4 // Author: wxWidgets team
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
11 wxVector<T> is a template class which implements most of the @c std::vector
12 class and can be used like it.
14 If wxWidgets is compiled in STL mode, wxVector will just be a typedef to
15 @c std::vector. Just like for @c std::vector, objects stored in wxVector<T>
16 need to be @e assignable but don't have to be @e "default constructible".
18 Please refer to the STL documentation for further information.
23 @see @ref overview_container, wxList<T>, wxArray<T>, wxVectorSort<T>
29 typedef size_t size_type
;
30 typedef size_t difference_type
;
32 typedef value_type
* pointer
;
33 typedef value_type
* iterator
;
34 typedef const value_type
* const_iterator
;
35 typedef value_type
& reference
;
43 Constructor initializing the vector with the given number of
44 default-constructed objects.
46 wxVector(size_type size
);
49 Constructor initializing the vector with the given number of
50 copies of the given object.
52 wxVector(size_type size
, const value_type
& value
);
55 Constructor initializing the vector with the elements in the given
58 The @a InputIterator template parameter must be an input iterator type.
59 This constructor adds all elements from @a first until, not not
60 including, @a last to the vector.
64 template <class InputIterator
>
65 wxVector(InputIterator first
, InputIterator last
);
70 wxVector(const wxVector
<T
>& c
);
78 Resizes the vector to @a n and assigns @a v to all elements.
84 void assign(size_type n
, const value_type
& v
);
87 Assigns the elements in the given range to the vector.
89 The @a InputIterator template parameter must be an input iterator type.
90 This method clears the vector and then adds all elements from @a first
91 until, not not including, @a last to it.
95 template <class InputIterator
>
96 void assign(InputIterator first
, InputIterator last
);
99 Returns item at position @a idx.
101 const value_type
& at(size_type idx
) const;
104 Returns item at position @a idx.
106 value_type
& at(size_type idx
);
109 Return the last item.
111 const value_type
& back() const;
114 Return the last item.
119 Return iterator to beginning of the vector.
121 const_iterator
begin() const;
124 Return iterator to beginning of the vector.
129 Return reverse iterator to end of the vector.
131 reverse_iterator
rbegin();
134 Return reverse iterator to beginning of the vector.
136 reverse_iterator
rend();
140 Returns vector's current capacity, i.e.\ how much memory is allocated.
144 size_type
capacity() const;
152 Returns @true if the vector is empty.
157 Returns iterator to the end of the vector.
159 const_iterator
end() const;
162 Returns iterator to the end of the vector.
167 Erase item pointed to by iterator @a it.
169 @return Iterator pointing to the item immediately after the erased one.
171 iterator
erase(iterator it
);
174 Erase items in the range @a first to @a last (@a last is not erased).
176 @return Iterator pointing to the item immediately after the erased
179 iterator
erase(iterator first
, iterator last
);
182 Returns the first item.
184 const value_type
& front() const;
187 Returns the first item.
192 Insert item @a v at given position @a it.
194 @return Iterator for the inserted item.
196 iterator
insert(iterator it
, const value_type
& v
= value_type());
201 wxVector
& operator=(const wxVector
& vb
);
204 Returns item at position @a idx.
206 const value_type
& operator[](size_type idx
) const;
209 Returns item at position @a idx.
211 value_type
& operator[](size_type idx
);
214 Removes the last item.
219 Adds an item to the end of the vector.
221 void push_back(const value_type
& v
);
224 Reserves memory for at least @a n items.
228 void reserve(size_type n
);
231 Makes the vector of size @a n.
233 If @a n is less than the current size(), the elements at the end of the
234 vector are erased. If it is greater, then the vector is completed with
235 either the copies of the given object @a v or @c value_type() objects
236 until it becomes of size @a n.
239 void resize(size_type n
);
240 void resize(size_type n
, const value_type
& v
);
244 Returns the size of the vector.
246 size_type
size() const;
249 Efficiently exchanges contents of this vector with another one.
251 After the execution of this function the contents of this vector is
252 equal to the original contents of @a v and the contents of @a v becomes
253 the original contents of this vector without copying the data.
257 void swap(wxVector
& v
);
262 Sort the contents of a @c wxVector<T>. In a STL build this function will
263 be defined as a thin wrapper around std::sort. To be sortable the
264 contained type must support the less-than operator.
267 wxVector<SomeClass> v;
268 ... // items are added to the vector v...
275 void wxVectorSort(wxVector
<T
>& v
);