From 102540a046870ad87b46c6016743a2ab90dc0f13 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 24 Nov 2012 17:36:44 +0000 Subject: [PATCH] Add wxList::AsVector<>() helper. 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 | 1 + include/wx/list.h | 18 ++++++++++++++++++ interface/wx/list.h | 7 +++++++ 3 files changed, 26 insertions(+) diff --git a/docs/changes.txt b/docs/changes.txt index f364429e5d..38b75000a3 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -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): diff --git a/include/wx/list.h b/include/wx/list.h index cb6bcbae62..ed34130a16 100644 --- a/include/wx/list.h +++ b/include/wx/list.h @@ -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 + wxVector AsVector() const + { + wxVector vector(size()); + size_t i = 0; + + for ( const_iterator it = begin(); it != end(); ++it ) + { + vector[i++] = static_cast(*it); + } + + return vector; + } +#endif // !__VISUALC6__ + }; #if !wxUSE_STD_CONTAINERS diff --git a/interface/wx/list.h b/interface/wx/list.h index 7d2f566c63..eb26deab15 100644 --- a/interface/wx/list.h +++ b/interface/wx/list.h @@ -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 AsVector() const; }; -- 2.47.2