]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/dynarray.cpp
extracted common code into a single wxfileDialogBase class (patch 758901)
[wxWidgets.git] / src / common / dynarray.cpp
index 39db10d384bab1b0c0acab4c136212f113f8cde8..63d9e7b5caa59b931f7ec5259b7b8b1a2e4b1c2f 100644 (file)
@@ -78,28 +78,29 @@ 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
 
 #define _WX_DEFINE_BASEARRAY_NOCOMMON(T, name)                              \
 size_t name::IndexForInsert(T lItem, CMPFUNC fnCompare) const               \
 {                                                                           \
-    Predicate p(fnCompare);                                                 \
+    Predicate p((SCMPFUNC)fnCompare);                                       \
     const_iterator it = std::lower_bound(begin(), end(), lItem, p);         \
     return it - begin();                                                    \
 }                                                                           \
                                                                             \
 int name::Index(T lItem, CMPFUNC fnCompare) const                           \
 {                                                                           \
-    size_t n = IndexForInsert(lItem, fnCompare);                            \
-                                                                            \
-    return (n >= size() ||                                                  \
-           (*fnCompare)(&lItem, &(*this)[n])) ? wxNOT_FOUND : (int)n;       \
+    Predicate p((SCMPFUNC)fnCompare);                                       \
+    const_iterator it = std::lower_bound(begin(), end(), lItem, p);         \
+    return (it != end() &&                                                  \
+            p(lItem, *it)) ? (int)(it - begin()) : wxNOT_FOUND;             \
 }                                                                           \
                                                                             \
 void name::Shrink()                                                         \