]> git.saurik.com Git - wxWidgets.git/commitdiff
made wxArrayString::assign(iterator, iterator) a template function; also fixed a...
authorVadim Zeitlin <vadim@wxwidgets.org>
Thu, 12 Feb 2009 12:09:13 +0000 (12:09 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Thu, 12 Feb 2009 12:09:13 +0000 (12:09 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@58843 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/arrstr.h
interface/wx/arrstr.h
src/common/arrstr.cpp
tests/arrays/arrays.cpp

index cdba3806d37e9f96fdda913db69198c05302c07e..14c291b2494d3219dc42027e34754dc1e7e4292f 100644 (file)
@@ -91,6 +91,18 @@ public:
 
 #else // if !wxUSE_STL
 
+// this shouldn't be defined for compilers not supporting template methods or
+// without std::distance() -- and if all of the currently supported compilers
+// do have it, then it can just be removed and wxHAS_VECTOR_TEMPLATE_ASSIGN
+// code always used
+#define wxHAS_VECTOR_TEMPLATE_ASSIGN
+
+#ifdef wxHAS_VECTOR_TEMPLATE_ASSIGN
+    #include "wx/beforestd.h"
+    #include <iterator>
+    #include "wx/afterstd.h"
+#endif // wxHAS_VECTOR_TEMPLATE_ASSIGN
+
 class WXDLLIMPEXP_BASE wxArrayString
 {
 public:
@@ -265,7 +277,26 @@ public:
   wxArrayString(const_iterator first, const_iterator last)
     { Init(false); assign(first, last); }
   wxArrayString(size_type n, const_reference v) { Init(false); assign(n, v); }
-  void assign(const_iterator first, const_iterator last);
+
+#ifdef wxHAS_VECTOR_TEMPLATE_ASSIGN
+  template <class Iterator>
+  void assign(Iterator first, Iterator last)
+  {
+      clear();
+      reserve(std::distance(first, last));
+      for(; first != last; ++first)
+          push_back(*first);
+  }
+#else // !wxHAS_VECTOR_TEMPLATE_ASSIGN
+  void assign(const_iterator first, const_iterator last)
+  {
+      clear();
+      reserve(last - first);
+      for(; first != last; ++first)
+          push_back(*first);
+  }
+#endif // wxHAS_VECTOR_TEMPLATE_ASSIGN/!wxHAS_VECTOR_TEMPLATE_ASSIGN
+
   void assign(size_type n, const_reference v)
     { clear(); Add(v, n); }
   reference back() { return *(end() - 1); }
index 228126f769e42627e40491e17b25c3a48aefa89f..46d3fed6b6bd0c97c75b12e1359699f3dc7a38e3 100644 (file)
     a specialization of wxArray class for the wxString member data: it is not
     implemented like this, but it does have all of the wxArray functions.
 
-    @todo what about stl? how does it integrate?
+    It also has the full set of <tt>std::vector<wxString></tt> compatible
+    methods, including nested @c iterator and @c const_iterator classes which
+    should be used in the new code for forward compatibility with the future
+    wxWidgets versions.
 
     @library{wxbase}
     @category{containers}
index bb22e7e88c50ad152a98506968a9db105a482def..fa303bd756e3548e73331e76ccd5e45e1adb1edd 100644 (file)
@@ -378,13 +378,6 @@ void wxArrayString::Remove(const wxString& sz)
   RemoveAt(iIndex);
 }
 
-void wxArrayString::assign(const_iterator first, const_iterator last)
-{
-    reserve(last - first);
-    for(; first != last; ++first)
-        push_back(*first);
-}
-
 // ----------------------------------------------------------------------------
 // sorting
 // ----------------------------------------------------------------------------
index a5a26644f3e631a8c365acc8afebd2d2669859fd..0913b8ab8e299338166d482457a02a1c46a9da06 100644 (file)
@@ -314,6 +314,19 @@ void ArraysTestCase::wxStringArrayTest()
                                           _T("a") ,
                                           _T("a") ,
                                           _T("a") ) );
+
+    a5.assign(a1.end(), a1.end());
+    CPPUNIT_ASSERT( a5.empty() );
+
+    a5.assign(a1.begin(), a1.end());
+    CPPUNIT_ASSERT( a5 == a1 );
+
+#ifdef wxHAS_VECTOR_TEMPLATE_ASSIGN
+    const wxString months[] = { "Jan", "Feb", "Mar" };
+    a5.assign(months, months + WXSIZEOF(months));
+    CPPUNIT_ASSERT_EQUAL( WXSIZEOF(months), a5.size() );
+    CPPUNIT_ASSERT( COMPARE_3_VALUES(a5, "Jan", "Feb", "Mar") );
+#endif // wxHAS_VECTOR_TEMPLATE_ASSIGN
 }
 
 void ArraysTestCase::wxStringArraySplitTest()