Add ctor and assign() taking an iterator range to wxVector<>.

Do it for consistency with wxArray and std::vector<>, even if the current
implementation is suboptimal.

See #15216.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@74045 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2013-05-22 14:13:26 +00:00
parent 41da7d974a
commit 4a8e979925
2 changed files with 45 additions and 0 deletions

View File

@@ -255,6 +255,13 @@ public:
Copy(c); Copy(c);
} }
template <class InputIterator>
wxVector(InputIterator first, InputIterator last)
: m_size(0), m_capacity(0), m_values(NULL)
{
assign(first, last);
}
~wxVector() ~wxVector()
{ {
clear(); clear();
@@ -268,6 +275,19 @@ public:
push_back(v); push_back(v);
} }
template <class InputIterator>
void assign(InputIterator first, InputIterator last)
{
clear();
// Notice that it would be nice to call reserve() here but we can't do
// it for arbitrary input iterators, we should have a dispatch on
// iterator type and call it if possible.
for ( InputIterator it = first; it != last; ++it )
push_back(*it);
}
void swap(wxVector& v) void swap(wxVector& v)
{ {
wxSwap(m_size, v.m_size); wxSwap(m_size, v.m_size);

View File

@@ -51,6 +51,19 @@ public:
*/ */
wxVector(size_type size, const value_type& value); wxVector(size_type size, const value_type& value);
/**
Constructor initializing the vector with the elements in the given
range.
The @a InputIterator template parameter must be an input iterator type.
This constructor adds all elements from @a first until, not not
including, @a last to the vector.
@since 2.9.5
*/
template <class InputIterator>
wxVector(InputIterator first, InputIterator last);
/** /**
Copy constructor. Copy constructor.
*/ */
@@ -70,6 +83,18 @@ public:
*/ */
void assign(size_type n, const value_type& v); void assign(size_type n, const value_type& v);
/**
Assigns the elements in the given range to the vector.
The @a InputIterator template parameter must be an input iterator type.
This method clears the vector and then adds all elements from @a first
until, not not including, @a last to it.
@since 2.9.5
*/
template <class InputIterator>
void assign(InputIterator first, InputIterator last);
/** /**
Returns item at position @a idx. Returns item at position @a idx.
*/ */