X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=flower%2Finclude%2Fstd-vector.hh;h=76a11bb9252237189463c667290df2cd01ecc183;hb=5b4b0d6e9a197e8f9eb085b7c2ad78b8be3e5cfc;hp=da3686a07c813eb7ab036d3e151c7c6af762d4ee;hpb=3f1e8dc68d267b039b9e231564d0e60c67d14429;p=lilypond.git diff --git a/flower/include/std-vector.hh b/flower/include/std-vector.hh index da3686a07c..76a11bb925 100644 --- a/flower/include/std-vector.hh +++ b/flower/include/std-vector.hh @@ -3,7 +3,7 @@ source file of the GNU LilyPond music typesetter - (c) 2006 Jan Nieuwenhuizen + (c) 2006--2008 Jan Nieuwenhuizen */ #ifndef STD_VECTOR_HH @@ -22,10 +22,11 @@ #include /* find, reverse, sort */ #include /* unary_function */ #include +#include using namespace std; -#if HAVE_BOOST_LAMBDA +#if HAVE_BOOST_LAMBDA_LAMBDA_HPP #include #endif @@ -191,46 +192,17 @@ binary_search (vector const &v, return lb; } -#if 0 -/* FIXME: the COMPARE functionality is broken? */ -template +template void -vector_sort (vector &v, int (*compare) (T const &, T const &), - vsize lower=VPOS, vsize upper=VPOS) +vector_sort (vector &v, + Compare less, + vsize b=0, vsize e=VPOS) { - typename vector::iterator b = v.begin (); - typename vector::iterator e = v.begin (); - if (lower == VPOS) - { - lower = 0; - upper = v.size (); - } - sort (b + lower, e + upper, compare); -} -#else + if (e == VPOS) + e = v.size (); -// ugh, c&p -template void -vector_sort (vector &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); + sort (v.begin () + b, v.begin () + e, less); } -#endif template void @@ -255,7 +227,7 @@ find (vector const &v, T const &key) return find (v.begin (), v.end (), key); } -#if HAVE_BOOST_LAMBDA +#if HAVE_BOOST_LAMBDA_LAMBDA_HPP #include using namespace boost::lambda; template @@ -287,6 +259,7 @@ junk_pointers (vector &v) #endif /* HAVE_BOOST_LAMBDA */ vector string_split (string str, char c); +string string_join (vector const &strs, string infix); #define iterof(i,s) typeof((s).begin()) i((s).begin())