2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2006--2015 Jan Nieuwenhuizen <janneke@gnu.org>
6 LilyPond is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 LilyPond is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
26 leads to dubious crashes - libstdc++ bug?
29 #define _GLIBCXX_DEBUG 1
33 #include "config.hh" /* needed at least for HAVE_STL_DATA_METHOD */
34 #include <algorithm> /* find, reverse, sort */
35 #include <functional> /* unary_function */
42 int default_compare (T const &a, T const &b)
53 int default_compare (T *const &a, T *const &b)
68 #define VPOS ((vsize) -1)
75 boundary (vector<T> const &v, int dir, vsize i)
78 return v[dir == -1 ? i : v.size () - 1 - i];
83 boundary (vector<T> &v, int dir, vsize i)
86 return v[dir == -1 ? i : v.size () - 1 - i];
91 back (vector<T> const &v, vsize i)
93 return v[v.size () - i - 1];
98 back (vector<T> &v, vsize i)
100 return v[v.size () - i - 1];
105 concat (vector<T> &v, vector<T> const &w)
107 v.insert (v.end (), w.begin (), w.end ());
110 template<typename T, typename Compare>
112 lower_bound (vector<T> const &v,
115 vsize b = 0, vsize e = VPOS)
119 typename vector<T>::const_iterator i = lower_bound (v.begin () + b,
124 return i - v.begin ();
127 template<typename T, typename Compare>
129 upper_bound (vector<T> const &v,
132 vsize b = 0, vsize e = VPOS)
137 typename vector<T>::const_iterator i = upper_bound (v.begin () + b,
142 return i - v.begin ();
145 template<typename T, typename Compare>
147 binary_search (vector<T> const &v,
150 vsize b = 0, vsize e = VPOS)
152 vsize lb = lower_bound (v, key, less, b, e);
154 if (lb == v.size () || less (key, v[lb]))
159 template<typename T, typename Compare>
161 vector_sort (vector<T> &v,
163 vsize b = 0, vsize e = VPOS)
168 sort (v.begin () + b, v.begin () + e, less);
173 reverse (vector<T> &v)
175 // CHECKME: for a simple vector, like vector<int>, this should
177 reverse (v.begin (), v.end ());
184 v.erase (unique (v.begin (), v.end ()), v.end ());
188 typename vector<T>::const_iterator
189 find (vector<T> const &v, T const &key)
191 return find (v.begin (), v.end (), key);
194 template<typename T> struct del : public unary_function<T, void>
196 void operator () (T x)
205 junk_pointers (vector<T> &v)
208 for_each (v.begin (), v.end (), del<T> ());
212 vector<string> string_split (string str, char c);
213 string string_join (vector<string> const &strs, const string &infix);
215 #define iterof(i,s) typeof((s).begin()) i((s).begin())
217 #endif /* STD_VECTOR_HH */