]> git.saurik.com Git - wxWidgets.git/commitdiff
Add wxList::AsVector<>() helper.
authorVadim Zeitlin <vadim@wxwidgets.org>
Sat, 24 Nov 2012 17:36:44 +0000 (17:36 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sat, 24 Nov 2012 17:36:44 +0000 (17:36 +0000)
This can be useful in legacy code using wxList to progressively replace it
with wxVector.

See #14814.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@73003 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/changes.txt
include/wx/list.h
interface/wx/list.h

index f364429e5d1294ae92c10c080f78aedeb3def820..38b75000a38198d8efb227ae81fbd78623c21637 100644 (file)
@@ -644,6 +644,7 @@ All:
 - Added wxDir::GetNameWithSep().
 - Allow unloading wxPluginLibrary objects in any order (manyleaves).
 - Fix passing strings with embedded NULs in wxThreadEvents (Steffen Olszewski).
+- Add wxList::AsVector<>() helper (troelsk).
 
 All (GUI):
 
index cb6bcbae62a60459b2ce2735998e619fb90ffaae..ed34130a165d7088be2ea91e421ffa01a9621025 100644 (file)
@@ -32,6 +32,7 @@
 #include "wx/defs.h"
 #include "wx/object.h"
 #include "wx/string.h"
+#include "wx/vector.h"
 
 #if wxUSE_STD_CONTAINERS
     #include "wx/beforestd.h"
@@ -1215,6 +1216,23 @@ public:
     // compatibility methods
     void Sort(wxSortCompareFunction compfunc) { wxListBase::Sort(compfunc); }
 #endif // !wxUSE_STD_CONTAINERS
+
+#ifndef __VISUALC6__
+    template<typename T>
+    wxVector<T> AsVector() const
+    {
+        wxVector<T> vector(size());
+        size_t i = 0;
+
+        for ( const_iterator it = begin(); it != end(); ++it )
+        {
+            vector[i++] = static_cast<T>(*it);
+        }
+
+        return vector;
+    }
+#endif // !__VISUALC6__
+
 };
 
 #if !wxUSE_STD_CONTAINERS
index 7d2f566c631d56a4eb84dfef2542121f3d4e31e8..eb26deab15df844c797426cc8eee071e8a0e3be0 100644 (file)
@@ -391,6 +391,13 @@ public:
         Returns the size of the list.
     */
     size_type size() const;
+
+    /**
+        Returns a wxVector holding the list elements.
+
+        @since 2.9.5
+    */
+    wxVector<T> AsVector() const;
 };