2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2006--2011 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 <algorithm> /* find, reverse, sort */
34 #include <functional> /* unary_function */
41 int default_compare (T const &a, T const &b)
52 int default_compare (T *const &a, T *const &b)
67 #define VPOS ((vsize) -1)
70 #if HAVE_STL_DATA_METHOD
72 #else /* !HAVE_STL_DATA_METHOD */
73 #define vector __flower_vector
80 /* Interface without pointer arithmetic (iterator) semantics. */
81 template<typename T, typename A = std::allocator<T> >
82 class vector : public __flower_vector<T, A>
85 typedef typename __flower_vector<T>::iterator iterator;
86 typedef typename __flower_vector<T>::const_iterator const_iterator;
88 vector<T, A> () : __flower_vector<T, A> ()
92 vector<T, A> (vector<T, A> const &v) : __flower_vector<T, A> (v)
96 vector<T, A> (const_iterator b, const_iterator e) : __flower_vector<T, A> (b, e)
113 } /* namespace std */
115 #endif /* !HAVE_STL_DATA_METHOD */
119 boundary (vector<T> const &v, int dir, vsize i)
122 return v[dir == -1 ? i : v.size () - 1 - i];
127 boundary (vector<T> &v, int dir, vsize i)
130 return v[dir == -1 ? i : v.size () - 1 - i];
135 back (vector<T> const &v, vsize i)
137 return v[v.size () - i - 1];
142 back (vector<T> &v, vsize i)
144 return v[v.size () - i - 1];
149 concat (vector<T> &v, vector<T> const &w)
151 v.insert (v.end (), w.begin (), w.end ());
154 template<typename T, typename Compare>
156 lower_bound (vector<T> const &v,
159 vsize b = 0, vsize e = VPOS)
163 typename vector<T>::const_iterator i = lower_bound (v.begin () + b,
168 return i - v.begin ();
171 template<typename T, typename Compare>
173 upper_bound (vector<T> const &v,
176 vsize b = 0, vsize e = VPOS)
181 typename vector<T>::const_iterator i = upper_bound (v.begin () + b,
186 return i - v.begin ();
189 template<typename T, typename Compare>
191 binary_search (vector<T> const &v,
193 Compare less = less<T> (),
194 vsize b = 0, vsize e = VPOS)
196 vsize lb = lower_bound (v, key, less, b, e);
198 if (lb == v.size () || less (key, v[lb]))
203 template<typename T, typename Compare>
205 vector_sort (vector<T> &v,
207 vsize b = 0, vsize e = VPOS)
212 sort (v.begin () + b, v.begin () + e, less);
217 reverse (vector<T> &v)
219 // CHECKME: for a simple vector, like vector<int>, this should
221 reverse (v.begin (), v.end ());
228 v.erase (unique (v.begin (), v.end ()), v.end ());
232 typename vector<T>::const_iterator
233 find (vector<T> const &v, T const &key)
235 return find (v.begin (), v.end (), key);
238 template<typename T> struct del : public unary_function<T, void>
240 void operator () (T x)
249 junk_pointers (vector<T> &v)
252 for_each (v.begin (), v.end (), del<T> ());
256 vector<string> string_split (string str, char c);
257 string string_join (vector<string> const &strs, string infix);
259 #define iterof(i,s) typeof((s).begin()) i((s).begin())
261 #endif /* STD_VECTOR_HH */