source file of the GNU LilyPond music typesetter
- (c) 2006 Jan Nieuwenhuizen <janneke@gnu.org>
+ (c) 2006--2008 Jan Nieuwenhuizen <janneke@gnu.org>
*/
#ifndef STD_VECTOR_HH
#define STD_VECTOR_HH
+#if 0
+
+/*
+ leads to dubious crashes - libstdc++ bug?
+*/
+#ifndef NDEBUG
+#define _GLIBCXX_DEBUG 1
+#endif
+#endif
+
#include <algorithm> /* find, reverse, sort */
#include <functional> /* unary_function */
#include <cassert>
+#include <string>
using namespace std;
-#if HAVE_BOOST_LAMBDA
+#if HAVE_BOOST_LAMBDA_LAMBDA_HPP
#include <boost/lambda/lambda.hpp>
#endif
return lb;
}
-#if 0
-/* FIXME: the COMPARE functionality is broken? */
-template<typename T>
+template<typename T, typename Compare>
void
-vector_sort (vector<T> &v, int (*compare) (T const &, T const &),
- vsize lower=VPOS, vsize upper=VPOS)
+vector_sort (vector<T> &v,
+ Compare less,
+ vsize b=0, vsize e=VPOS)
{
- typename vector<T>::iterator b = v.begin ();
- typename vector<T>::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<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);
+ sort (v.begin () + b, v.begin () + e, less);
}
-#endif
template<typename T>
void
return find (v.begin (), v.end (), key);
}
-#if HAVE_BOOST_LAMBDA
+#if HAVE_BOOST_LAMBDA_LAMBDA_HPP
#include <boost/lambda/lambda.hpp>
using namespace boost::lambda;
template<typename T>
#endif /* HAVE_BOOST_LAMBDA */
vector<string> string_split (string str, char c);
+string string_join (vector<string> const &strs, string infix);
#define iterof(i,s) typeof((s).begin()) i((s).begin())