Sun, 20 Jul 2014 17:25:36 +0300
- massive refactoring
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1 | /* |
133
dbbdb870c835
- changed all source files to use my correct legal name instead of my calling name
Teemu Piippo <crimsondusk64@gmail.com>
parents:
125
diff
changeset
|
2 | Copyright 2012-2014 Teemu Piippo |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
3 | All rights reserved. |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
4 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
5 | Redistribution and use in source and binary forms, with or without |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
6 | modification, are permitted provided that the following conditions |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
7 | are met: |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
8 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
9 | 1. Redistributions of source code must retain the above copyright |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
10 | notice, this list of conditions and the following disclaimer. |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
11 | 2. Redistributions in binary form must reproduce the above copyright |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
12 | notice, this list of conditions and the following disclaimer in the |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
13 | documentation and/or other materials provided with the distribution. |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
14 | 3. The name of the author may not be used to endorse or promote products |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
15 | derived from this software without specific prior written permission. |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
16 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
17 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
18 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
19 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
20 | IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
21 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
22 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
23 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
24 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
26 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
27 | */ |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
28 | |
124
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
29 | #ifndef BOTC_LIST_H |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
30 | #define BOTC_LIST_H |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
31 | |
125
85814c0918c5
- now with a smarter assert
Teemu Piippo <crimsondusk64@gmail.com>
parents:
124
diff
changeset
|
32 | #include "macros.h" |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
33 | #include <algorithm> |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
34 | #include <deque> |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
35 | #include <initializer_list> |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
36 | |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
37 | template<typename T> |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
38 | class List |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
39 | { |
124
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
40 | public: |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
41 | using Iterator = typename std::deque<T>::iterator; |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
42 | using ConstIterator = typename std::deque<T>::const_iterator; |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
43 | using ReverseIterator = typename std::deque<T>::reverse_iterator; |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
44 | using ConstReverseIterator = typename std::deque<T>::const_reverse_iterator; |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
45 | |
124
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
46 | List(); |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
47 | List (const std::deque<T>& a); |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
48 | List (std::initializer_list<T>and a); |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
49 | |
124
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
50 | inline T& append (const T& value); |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
51 | inline Iterator begin(); |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
52 | inline ConstIterator begin() const; |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
53 | inline void clear(); |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
54 | inline bool contains (const T& a) const; |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
55 | inline ConstReverseIterator crbegin() const; |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
56 | inline ConstReverseIterator crend() const; |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
57 | inline const std::deque<T>& deque() const; |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
58 | inline Iterator end(); |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
59 | inline ConstIterator end() const; |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
60 | int find (const T& needle) const; |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
61 | inline const T& first() const; |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
62 | inline void insert (int pos, const T& value); |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
63 | inline bool isEmpty() const; |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
64 | inline const T& last() const; |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
65 | void merge (const List<T>& other); |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
66 | bool pop (T& val); |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
67 | inline T& prepend (const T& value); |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
68 | inline ReverseIterator rbegin(); |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
69 | inline void removeAt (int pos); |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
70 | void removeDuplicates(); |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
71 | void removeOne (const T& it); |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
72 | inline ReverseIterator rend(); |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
73 | inline void resize (int size); |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
74 | List<T> reverse() const; |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
75 | inline int size() const; |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
76 | inline void sort(); |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
77 | List<T> splice (int a, int b) const; |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
78 | |
124
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
79 | inline List<T>& operator<< (const T& value); |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
80 | inline List<T>& operator<< (const List<T>& vals); |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
81 | inline T& operator[] (int n); |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
82 | inline const T& operator[] (int n) const; |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
83 | inline List<T> operator+ (const List<T>& other) const; |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
84 | |
124
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
85 | private: |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
86 | std::deque<T> _deque; |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
87 | }; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
88 | |
124
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
89 | template<typename T> |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
90 | List<T>& operator>> (const T& value, List<T>& haystack); |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
91 | |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
92 | // |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
93 | // --- IMPLEMENTATIONS |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
94 | // |
124
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
95 | |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
96 | template<typename T> |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
97 | List<T>::List() {} |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
98 | |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
99 | template<typename T> |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
100 | List<T>::List (const std::deque<T>& other) : |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
101 | _deque (other) {} |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
102 | |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
103 | template<typename T> |
134
eca2fc0acaa2
- massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
133
diff
changeset
|
104 | List<T>::List (std::initializer_list<T>and a) : |
124
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
105 | _deque (a) {} |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
106 | |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
107 | template<typename T> |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
108 | inline typename List<T>::Iterator List<T>::begin() |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
109 | { |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
110 | return _deque.begin(); |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
111 | } |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
112 | |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
113 | template<typename T> |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
114 | inline typename List<T>::ConstIterator List<T>::begin() const |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
115 | { |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
116 | return _deque.cbegin(); |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
117 | } |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
118 | |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
119 | template<typename T> |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
120 | inline typename List<T>::Iterator List<T>::end() |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
121 | { |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
122 | return _deque.end(); |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
123 | } |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
124 | |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
125 | template<typename T> |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
126 | inline typename List<T>::ConstIterator List<T>::end() const |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
127 | { |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
128 | return _deque.cend(); |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
129 | } |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
130 | |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
131 | template<typename T> |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
132 | inline typename List<T>::ReverseIterator List<T>::rbegin() |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
133 | { |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
134 | return _deque.rbegin(); |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
135 | } |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
136 | |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
137 | template<typename T> |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
138 | inline typename List<T>::ConstReverseIterator List<T>::crbegin() const |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
139 | { |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
140 | return _deque.crbegin(); |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
141 | } |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
142 | |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
143 | template<typename T> |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
144 | inline typename List<T>::ReverseIterator List<T>::rend() |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
145 | { |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
146 | return _deque.rend(); |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
147 | } |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
148 | |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
149 | template<typename T> |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
150 | inline typename List<T>::ConstReverseIterator List<T>::crend() const |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
151 | { |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
152 | return _deque.crend(); |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
153 | } |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
154 | |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
155 | template<typename T> |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
156 | void List<T>::removeAt (int pos) |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
157 | { |
125
85814c0918c5
- now with a smarter assert
Teemu Piippo <crimsondusk64@gmail.com>
parents:
124
diff
changeset
|
158 | ASSERT_LT (pos, size()); |
124
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
159 | _deque.erase (_deque.begin() + pos); |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
160 | } |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
161 | |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
162 | template<typename T> |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
163 | inline T& List<T>::prepend (const T& value) |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
164 | { |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
165 | _deque.push_front (value); |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
166 | return _deque[0]; |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
167 | } |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
168 | |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
169 | template<typename T> |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
170 | inline T& List<T>::append (const T& value) |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
171 | { |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
172 | _deque.push_back (value); |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
173 | return _deque[_deque.size() - 1]; |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
174 | } |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
175 | |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
176 | template<typename T> |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
177 | void List<T>::merge (const List<T>& other) |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
178 | { |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
179 | resize (size() + other.size()); |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
180 | std::copy (other.begin(), other.end(), begin() + other.size()); |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
181 | } |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
182 | |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
183 | template<typename T> |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
184 | bool List<T>::pop (T& val) |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
185 | { |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
186 | if (isEmpty()) |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
187 | return false; |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
188 | |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
189 | val = _deque[size() - 1]; |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
190 | _deque.erase (_deque.end() - 1); |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
191 | return true; |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
192 | } |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
193 | |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
194 | template<typename T> |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
195 | inline List<T>& List<T>::operator<< (const T& value) |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
196 | { |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
197 | append (value); |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
198 | return *this; |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
199 | } |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
200 | |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
201 | template<typename T> |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
202 | inline List<T>& List<T>::operator<< (const List<T>& vals) |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
203 | { |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
204 | merge (vals); |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
205 | return *this; |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
206 | } |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
207 | |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
208 | template<typename T> |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
209 | List<T> List<T>::reverse() const |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
210 | { |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
211 | List<T> rev; |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
212 | std::copy (rbegin(), rend(), rev.begin()); |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
213 | return rev; |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
214 | } |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
215 | |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
216 | template<typename T> |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
217 | inline void List<T>::clear() |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
218 | { |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
219 | _deque.clear(); |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
220 | } |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
221 | |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
222 | template<typename T> |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
223 | inline void List<T>::insert (int pos, const T& value) |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
224 | { |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
225 | _deque.insert (_deque.begin() + pos, value); |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
226 | } |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
227 | |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
228 | template<typename T> |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
229 | void List<T>::removeDuplicates() |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
230 | { |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
231 | sort(); |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
232 | resize (std::distance (begin(), std::unique (begin(), end()))); |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
233 | } |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
234 | |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
235 | template<typename T> |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
236 | int List<T>::size() const |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
237 | { |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
238 | return _deque.size(); |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
239 | } |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
240 | |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
241 | template<typename T> |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
242 | inline T& List<T>::operator[] (int n) |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
243 | { |
125
85814c0918c5
- now with a smarter assert
Teemu Piippo <crimsondusk64@gmail.com>
parents:
124
diff
changeset
|
244 | ASSERT_LT (n, size()); |
124
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
245 | return _deque[n]; |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
246 | } |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
247 | |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
248 | template<typename T> |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
249 | inline const T& List<T>::operator[] (int n) const |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
250 | { |
125
85814c0918c5
- now with a smarter assert
Teemu Piippo <crimsondusk64@gmail.com>
parents:
124
diff
changeset
|
251 | ASSERT_LT (n, size()); |
124
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
252 | return _deque[n]; |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
253 | } |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
254 | |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
255 | template<typename T> |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
256 | inline void List<T>::resize (int size) |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
257 | { |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
258 | _deque.resize (size); |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
259 | } |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
260 | |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
261 | template<typename T> |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
262 | inline void List<T>::sort() |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
263 | { |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
264 | std::sort (begin(), end()); |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
265 | } |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
266 | |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
267 | template<typename T> |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
268 | int List<T>::find (const T& needle) const |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
269 | { |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
270 | auto it = std::find (_deque.cbegin(), _deque.cend(), needle); |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
271 | |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
272 | if (it == _deque.end()) |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
273 | return -1; |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
274 | |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
275 | return it - _deque.cbegin(); |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
276 | } |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
277 | |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
278 | template<typename T> |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
279 | void List<T>::removeOne (const T& a) |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
280 | { |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
281 | auto it = std::find (_deque.begin(), _deque.end(), a); |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
282 | |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
283 | if (it != _deque.end()) |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
284 | _deque.erase (it); |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
285 | } |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
286 | |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
287 | template<typename T> |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
288 | inline bool List<T>::isEmpty() const |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
289 | { |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
290 | return size() == 0; |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
291 | } |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
292 | |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
293 | template<typename T> |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
294 | List<T> List<T>::splice (int a, int b) const |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
295 | { |
125
85814c0918c5
- now with a smarter assert
Teemu Piippo <crimsondusk64@gmail.com>
parents:
124
diff
changeset
|
296 | ASSERT_RANGE (a, 0, size() - 1) |
85814c0918c5
- now with a smarter assert
Teemu Piippo <crimsondusk64@gmail.com>
parents:
124
diff
changeset
|
297 | ASSERT_RANGE (b, 0, size() - 1) |
85814c0918c5
- now with a smarter assert
Teemu Piippo <crimsondusk64@gmail.com>
parents:
124
diff
changeset
|
298 | ASSERT_LT_EQ (a, b) |
124
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
299 | List<T> result; |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
300 | |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
301 | for (int i = a; i <= b; ++i) |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
302 | result << operator[] (i); |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
303 | |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
304 | return result; |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
305 | } |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
306 | |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
307 | template<typename T> |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
308 | inline const std::deque<T>& List<T>::deque() const |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
309 | { |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
310 | return _deque; |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
311 | } |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
312 | |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
313 | template<typename T> |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
314 | inline const T& List<T>::first() const |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
315 | { |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
316 | return *_deque.cbegin(); |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
317 | } |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
318 | |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
319 | template<typename T> |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
320 | inline const T& List<T>::last() const |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
321 | { |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
322 | return *(_deque.cend() - 1); |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
323 | } |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
324 | |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
325 | template<typename T> |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
326 | inline bool List<T>::contains (const T& a) const |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
327 | { |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
328 | return std::find (_deque.cbegin(), _deque.cend(), a) != _deque.end(); |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
329 | } |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
330 | |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
331 | template<typename T> |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
332 | inline List<T> List<T>::operator+ (const List<T>& other) const |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
333 | { |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
334 | List<T> out (*this); |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
335 | out.merge (other); |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
336 | return out; |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
337 | } |
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
338 | |
119
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
339 | template<typename T> |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
340 | List<T>& operator>> (const T& value, List<T>& haystack) |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
341 | { |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
342 | haystack.prepend (value); |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
343 | return haystack; |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
344 | } |
bdf8d46c145f
- renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
345 | |
124
a7b769a0e537
- commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
346 | #endif // BOTC_LIST_H |