From: Vadim Zeitlin Date: Wed, 22 May 2013 14:13:26 +0000 (+0000) Subject: Add ctor and assign() taking an iterator range to wxVector<>. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/4a8e979925e3edd58b33d968527a3f45bca1f008 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 --- diff --git a/include/wx/vector.h b/include/wx/vector.h index e33f523d1c..dffb19fc9d 100644 --- a/include/wx/vector.h +++ b/include/wx/vector.h @@ -255,6 +255,13 @@ public: Copy(c); } + template + wxVector(InputIterator first, InputIterator last) + : m_size(0), m_capacity(0), m_values(NULL) + { + assign(first, last); + } + ~wxVector() { clear(); @@ -268,6 +275,19 @@ public: push_back(v); } + template + 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) { wxSwap(m_size, v.m_size); diff --git a/interface/wx/vector.h b/interface/wx/vector.h index 21aaca5763..93af592cbe 100644 --- a/interface/wx/vector.h +++ b/interface/wx/vector.h @@ -51,6 +51,19 @@ public: */ 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 + wxVector(InputIterator first, InputIterator last); + /** Copy constructor. */ @@ -70,6 +83,18 @@ public: */ 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 + void assign(InputIterator first, InputIterator last); + /** Returns item at position @a idx. */