forked from andrewprock/ustl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ulist.h
78 lines (71 loc) · 3.13 KB
/
ulist.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// This file is part of the uSTL library, an STL implementation.
//
// Copyright (c) 2005 by Mike Sharov <[email protected]>
// This file is free software, distributed under the MIT License.
#pragma once
#include "uvector.h"
#include "uctralgo.h"
namespace ustl {
/// \class list ulist.h ustl.h
/// \ingroup Sequences
///
/// \brief Linked list, defined as an alias to vector.
///
template <typename T>
class list : public vector<T> {
public:
using size_type = typename vector<T>::size_type;
using iterator = typename vector<T>::iterator;
using const_iterator = typename vector<T>::const_iterator;
using reference = typename vector<T>::reference;
using const_reference = typename vector<T>::const_reference;
public:
inline list (void) : vector<T> () {}
inline explicit list (size_type n) : vector<T> (n) {}
inline list (size_type n, const T& v) : vector<T> (n, v) {}
inline list (const list<T>& v) : vector<T> (v) {}
inline list (const_iterator i1, const_iterator i2) : vector<T> (i1, i2) {}
inline list (list&& v) : vector<T> (move(v)) {}
inline list (std::initializer_list<T> v) : vector<T>(v) {}
inline list& operator= (list&& v) { vector<T>::operator= (move(v)); return *this; }
template <typename... Args>
inline void emplace_front (Args&&... args) { vector<T>::emplace (begin(), forward<Args>(args)...); }
inline void push_front (T&& v) { emplace_front (move(v)); }
inline size_type size (void) const { return vector<T>::size(); }
inline iterator begin (void) { return vector<T>::begin(); }
inline const_iterator begin (void) const { return vector<T>::begin(); }
inline iterator end (void) { return vector<T>::end(); }
inline const_iterator end (void) const { return vector<T>::end(); }
inline void push_front (const T& v) { this->insert (begin(), v); }
inline void pop_front (void) { this->erase (begin()); }
inline const_reference front (void) const { return *begin(); }
inline reference front (void) { return *begin(); }
inline void remove (const T& v) { ::ustl::remove (*this, v); }
template <typename Predicate>
inline void remove_if (Predicate p) { ::ustl::remove_if (*this, p); }
inline void reverse (void) { ::ustl::reverse (*this); }
inline void unique (void) { ::ustl::unique (*this); }
inline void sort (void) { ::ustl::sort (*this); }
void merge (list<T>& l);
void splice (iterator ip, list<T>& l, iterator first = nullptr, iterator last = nullptr);
};
/// Merges the contents with \p l. Assumes both lists are sorted.
template <typename T>
void list<T>::merge (list& l)
{
this->insert_space (begin(), l.size());
::ustl::merge (this->iat(l.size()), end(), l.begin(), l.end(), begin());
}
/// Moves the range [first, last) from \p l to this list at \p ip.
template <typename T>
void list<T>::splice (iterator ip, list<T>& l, iterator first, iterator last)
{
if (!first)
first = l.begin();
if (!last)
last = l.end();
this->insert (ip, first, last);
l.erase (first, last);
}
template <typename T> using deque = list<T>;
} // namespace ustl