Build system improvements
[ustl.git] / ulist.h
blob1644ccb58473974f1b78a51fcdb196dd02a2bf9d
1 // This file is part of the ustl library, an STL implementation.
2 //
3 // Copyright (C) 2005 by Mike Sharov <msharov@users.sourceforge.net>
4 // This file is free software, distributed under the MIT License.
5 //
6 // ulist.h
7 //
9 #ifndef ULIST_H_54E3B510498982C87A0A1E1932E6729D
10 #define ULIST_H_54E3B510498982C87A0A1E1932E6729D
12 #include "uvector.h"
13 #include "uctralgo.h"
15 namespace ustl {
17 /// \class list ulist.h ustl.h
18 /// \ingroup Sequences
19 ///
20 /// \brief Linked list, defined as an alias to vector.
21 ///
22 template <typename T>
23 class list : public vector<T> {
24 public:
25 typedef typename vector<T>::size_type size_type;
26 typedef typename vector<T>::iterator iterator;
27 typedef typename vector<T>::const_iterator const_iterator;
28 typedef typename vector<T>::reference reference;
29 typedef typename vector<T>::const_reference const_reference;
30 public:
31 inline list (void) : vector<T> () {}
32 inline explicit list (size_type n) : vector<T> (n) {}
33 inline list (size_type n, const T& v) : vector<T> (n, v) {}
34 inline list (const list<T>& v) : vector<T> (v) {}
35 inline list (const_iterator i1, const_iterator i2) : vector<T> (i1, i2) {}
36 inline size_type size (void) const { return (vector<T>::size()); }
37 inline iterator begin (void) { return (vector<T>::begin()); }
38 inline const_iterator begin (void) const { return (vector<T>::begin()); }
39 inline iterator end (void) { return (vector<T>::end()); }
40 inline const_iterator end (void) const { return (vector<T>::end()); }
41 inline void push_front (const T& v) { insert (begin(), v); }
42 inline void pop_front (void) { erase (begin()); }
43 inline const_reference front (void) const { return (*begin()); }
44 inline reference front (void) { return (*begin()); }
45 inline void remove (const T& v) { ::ustl::remove (*this, v); }
46 inline void unique (void) { ::ustl::unique (*this); }
47 inline void sort (void) { ::ustl::sort (*this); }
48 void merge (list<T>& l);
49 void splice (iterator ip, list<T>& l, iterator first = NULL, iterator last = NULL);
52 /// Merges the contents with \p l. Assumes both lists are sorted.
53 template <typename T>
54 void list<T>::merge (list& l)
56 list<T>::resize (size() + l.size());
57 iterator me = merge (begin(), end(), l.begin(), l.end(), begin());
58 list<T>::resize (distance (begin(), me));
61 /// Moves the range [first, last) from \p l to this list at \p ip.
62 template <typename T>
63 void list<T>::splice (iterator ip, list<T>& l, iterator first, iterator last)
65 if (!first)
66 first = l.begin();
67 if (!last)
68 last = l.end();
69 insert (ip, first, last);
70 l.erase (first, last);
73 #define deque list ///< list has all the functionality provided by deque
75 } // namespace ustl
77 #endif