]> git.donarmstrong.com Git - lilypond.git/blobdiff - flower/include/std-vector.hh
Fix some bugs in the dynamic engraver and PostScript backend
[lilypond.git] / flower / include / std-vector.hh
index bb60308d5d7c41a539f5764450e24a7c6802ab59..83e58d299ccbc180babe5a7f2aa34f2b1a5dbca7 100644 (file)
@@ -24,7 +24,7 @@ int default_compare (T const &a, T const &b)
 {
   if (a < b)
     return -1;
-  else if (a > b)
+  else if (b < a)
     return 1;
   else
     return 0;
@@ -42,7 +42,6 @@ int default_compare (T *const &a, T *const &b)
 }
 
 #include "compare.hh"
-#include "config.hh"
 
 #ifndef VSIZE
 #define VSIZE
@@ -60,27 +59,31 @@ typedef size_t vsize;
 namespace std {
 
   /* Interface without pointer arithmetic (iterator) semantics.  */
-  template<typename T>
-  class vector : public __vector<T>
+  template<typename T, typename A=std::allocator<T> >
+  class vector : public __vector<T, A>
   {
   public:
     typedef typename __vector<T>::iterator iterator;
     typedef typename __vector<T>::const_iterator const_iterator;
-    
-    vector<T> () : __vector<T> ()
+
+    vector<T, A> () : __vector<T, A> ()
     {
     }
-    
-    vector<T> (const_iterator b, const_iterator e) : __vector<T> (b, e)
+
+    vector<T, A> (vector<T, A> const& v) : __vector<T, A> (v)
     {
     }
-    
+
+    vector<T, A> (const_iterator b, const_iterator e) : __vector<T, A> (b, e)
+    {
+    }
+
     T*
     data ()
     {
       return &(*this)[0];
     }
-    
+
     T const*
     data () const
     {
@@ -88,32 +91,6 @@ namespace std {
     }
   };
 
-  /* FIXME: it appears that choosing this function is broken when stl
-     has no data () member too...  */
-  template<typename T>
-  void
-  binary_search_bounds (vector<T*> const &table,
-                       T const *key, int (*compare) (T *const &, T *const &),
-                       vsize *lo,
-                       vsize *hi)
-  {
-    vsize cmp;
-    int result;
-
-    /* binary search */
-    do
-      {
-       cmp = (*lo + *hi) / 2;
-
-       result = (*compare) ((T *) key, table[cmp]);
-
-       if (result < 0)
-         *hi = cmp;
-       else
-         *lo = cmp;
-      }
-    while (*hi - *lo > 1);
-  }
 } /* namespace std */
 
 #endif /* !HAVE_STL_DATA_METHOD */
@@ -154,7 +131,7 @@ concat (vector<T> &v, vector<T> const& w)
 {
   v.insert (v.end (), w.begin (), w.end ());
 }
-  
+
 template<class T>
 void
 binary_search_bounds (vector<T> const &table,
@@ -183,6 +160,31 @@ binary_search_bounds (vector<T> const &table,
   while (*hi - *lo > 1);
 }
 
+template<typename T>
+void
+binary_search_bounds (vector<T*> const &table,
+                     T const *key, int (*compare) (T *const &, T *const &),
+                     vsize *lo,
+                     vsize *hi)
+{
+  vsize cmp;
+  int result;
+
+  /* binary search */
+  do
+    {
+      cmp = (*lo + *hi) / 2;
+
+      result = (*compare) ((T *) key, table[cmp]);
+
+      if (result < 0)
+       *hi = cmp;
+      else
+       *lo = cmp;
+    }
+  while (*hi - *lo > 1);
+}
+
 #if 0
 /* FIXME: what if COMPARE is named: int operator == (T const&, T const&),
    wouldn't that work for most uses of BINARY_SEARCH?
@@ -270,7 +272,7 @@ vector_sort (vector<T> &v, int (*compare) (T const &, T const &),
   vector_sort (v, compare, last + 1, upper);
 }
 #endif
-  
+
 template<typename T>
 void
 reverse (vector<T> &v)
@@ -325,4 +327,8 @@ junk_pointers (vector<T> &v)
 }
 #endif /* HAVE_BOOST_LAMBDA */
 
+vector<string> string_split (string str, char c);
+
+#define iterof(i,s) typeof((s).begin()) i((s).begin())
+
 #endif /* STD_VECTOR_HH */