- // ugh, c&p
- template<typename T> void
- vector_sort (vector<T> &v, int (*compare) (T const &, T const &),
- vsize lower=VPOS, vsize upper=VPOS)
- {
- if (lower == VPOS)
- {
- lower = 0;
- upper = v.size () - 1;
- }
- if (upper == VPOS || lower >= upper)
- return;
- swap (v[lower], v[(lower + upper) / 2]);
- vsize last = lower;
- for (vsize i = lower +1; i <= upper; i++)
- if (compare (v[i], v[lower]) < 0)
- swap (v[++last], v[i]);
- swap (v[lower], v[last]);
- vector_sort (v, compare, lower, last - 1);
- vector_sort (v, compare, last + 1, upper);
- }
-#endif
-
- template<typename T>
- void
- reverse (vector<T> &v)
- {
- // CHECKME: for a simple vector, like vector<int>, this should
- // expand to memrev.
- ::std::reverse (v.begin (), v.end ());
- }
+template<typename T, typename Compare>
+vsize
+lower_bound (vector<T> const &v,
+ T const &key,
+ Compare less,
+ vsize b = 0, vsize e = VPOS)
+{
+ if (e == VPOS)
+ e = v.size ();
+ typename vector<T>::const_iterator i = lower_bound (v.begin () + b,
+ v.begin () + e,
+ key,
+ less);
+
+ return i - v.begin ();
+}