From: Mattia Barbon Date: Thu, 10 Jul 2003 19:32:04 +0000 (+0000) Subject: wxSortedArray::Add must return the index of the newly X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/6992d326eb1246d9d03f04245d0cd87eab65f6f7 wxSortedArray::Add must return the index of the newly inserted item. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@21875 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/dynarray.h b/include/wx/dynarray.h index c1d42f59f3..b022b49a9c 100644 --- a/include/wx/dynarray.h +++ b/include/wx/dynarray.h @@ -114,7 +114,7 @@ protected: \ size_t IndexForInsert(T lItem, CMPFUNC fnCompare) const; \ void Add(T lItem, size_t nInsert = 1) \ { insert(end(), nInsert, lItem); } \ - void Add(T lItem, CMPFUNC fnCompare); \ + size_t Add(T lItem, CMPFUNC fnCompare); \ void Insert(T lItem, size_t uiIndex, size_t nInsert = 1) \ { insert(begin() + uiIndex, nInsert, lItem); } \ void Remove(T lItem); \ @@ -170,7 +170,7 @@ protected: \ int Index(T lItem, CMPFUNC fnCompare) const; \ size_t IndexForInsert(T lItem, CMPFUNC fnCompare) const; \ void Add(T lItem, size_t nInsert = 1); \ - void Add(T lItem, CMPFUNC fnCompare); \ + size_t Add(T lItem, CMPFUNC fnCompare); \ void Insert(T lItem, size_t uiIndex, size_t nInsert = 1); \ void Remove(T lItem); \ void RemoveAt(size_t uiIndex, size_t nRemove = 1); \ @@ -488,8 +488,8 @@ public: \ void AddAt(T item, size_t index) \ { base::insert(begin() + index, item); } \ \ - void Add(T Item) \ - { base::Add(Item, (CMPFUNC)m_fnCompare); } \ + size_t Add(T Item) \ + { return base::Add(Item, (CMPFUNC)m_fnCompare); } \ \ void RemoveAt(size_t uiIndex, size_t nRemove = 1) \ { base::erase(begin() + uiIndex, begin() + uiIndex + nRemove); } \ diff --git a/src/common/dynarray.cpp b/src/common/dynarray.cpp index 39db10d384..038947c6ba 100644 --- a/src/common/dynarray.cpp +++ b/src/common/dynarray.cpp @@ -78,11 +78,12 @@ int name::Index(T lItem, bool bFromEnd) const \ } \ \ /* add item assuming the array is sorted with fnCompare function */ \ -void name::Add(T lItem, CMPFUNC fnCompare) \ +size_t name::Add(T lItem, CMPFUNC fnCompare) \ { \ - Insert(lItem, IndexForInsert(lItem, fnCompare)); \ -} \ - \ + size_t idx = IndexForInsert(lItem, fnCompare); \ + Insert(lItem, idx); \ + return idx; \ +} #if wxUSE_STL