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