src/list.h

Mon, 21 Jul 2014 17:14:42 +0300

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Mon, 21 Jul 2014 17:14:42 +0300
changeset 135
8b9132fea327
parent 134
eca2fc0acaa2
child 139
cf11621ae422
permissions
-rw-r--r--

- massive refactoring continues (doesn't compile yet)

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();
135
8b9132fea327 - massive refactoring continues (doesn't compile yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 134
diff changeset
47 List (std::size_t numvalues);
124
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
48 List (const std::deque<T>& a);
135
8b9132fea327 - massive refactoring continues (doesn't compile yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 134
diff changeset
49 List (std::initializer_list<T>&& a);
119
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
50
124
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
51 inline T& append (const T& value);
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
52 inline Iterator begin();
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
53 inline ConstIterator begin() const;
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
54 inline void clear();
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
55 inline bool contains (const T& a) const;
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
56 inline ConstReverseIterator crbegin() const;
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
57 inline ConstReverseIterator crend() const;
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
58 inline const std::deque<T>& deque() const;
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
59 inline Iterator end();
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
60 inline ConstIterator end() const;
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
61 int find (const T& needle) const;
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
62 inline const T& first() const;
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
63 inline void insert (int pos, const T& value);
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
64 inline bool isEmpty() const;
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
65 inline const T& last() const;
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
66 void merge (const List<T>& other);
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
67 bool pop (T& val);
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
68 inline T& prepend (const T& value);
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
69 inline ReverseIterator rbegin();
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
70 inline void removeAt (int pos);
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
71 void removeDuplicates();
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
72 void removeOne (const T& it);
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
73 inline ReverseIterator rend();
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
74 inline void resize (int size);
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
75 List<T> reverse() const;
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
76 inline int size() const;
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
77 inline void sort();
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
78 List<T> splice (int a, int b) const;
119
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
79
124
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
80 inline List<T>& operator<< (const T& value);
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
81 inline List<T>& operator<< (const List<T>& vals);
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
82 inline T& operator[] (int n);
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
83 inline const T& operator[] (int n) const;
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
84 inline List<T> operator+ (const List<T>& other) const;
119
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
85
124
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
86 private:
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
87 std::deque<T> _deque;
119
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
88 };
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
89
124
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
90 template<typename T>
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
91 List<T>& operator>> (const T& value, List<T>& haystack);
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 //
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
94 // --- IMPLEMENTATIONS
119
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
95 //
124
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
96
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
97 template<typename T>
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
98 List<T>::List() {}
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
99
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
100 template<typename T>
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
101 List<T>::List (const std::deque<T>& other) :
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
102 _deque (other) {}
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
103
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
104 template<typename T>
135
8b9132fea327 - massive refactoring continues (doesn't compile yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 134
diff changeset
105 List<T>::List (std::initializer_list< T > && a) :
124
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
106 _deque (a) {}
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
107
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
108 template<typename T>
135
8b9132fea327 - massive refactoring continues (doesn't compile yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 134
diff changeset
109 List<T>::List (std::size_t numvalues) :
8b9132fea327 - massive refactoring continues (doesn't compile yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 134
diff changeset
110 _deque (numvalues) {}
8b9132fea327 - massive refactoring continues (doesn't compile yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 134
diff changeset
111
8b9132fea327 - massive refactoring continues (doesn't compile yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 134
diff changeset
112 template<typename T>
124
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
113 inline typename List<T>::Iterator List<T>::begin()
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
114 {
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
115 return _deque.begin();
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
116 }
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 template<typename T>
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
119 inline typename List<T>::ConstIterator List<T>::begin() const
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
120 {
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
121 return _deque.cbegin();
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
122 }
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 template<typename T>
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
125 inline typename List<T>::Iterator List<T>::end()
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
126 {
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
127 return _deque.end();
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
128 }
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 template<typename T>
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
131 inline typename List<T>::ConstIterator List<T>::end() const
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
132 {
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
133 return _deque.cend();
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
134 }
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 template<typename T>
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
137 inline typename List<T>::ReverseIterator List<T>::rbegin()
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
138 {
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
139 return _deque.rbegin();
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
140 }
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 template<typename T>
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
143 inline typename List<T>::ConstReverseIterator List<T>::crbegin() const
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
144 {
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
145 return _deque.crbegin();
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
146 }
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 template<typename T>
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
149 inline typename List<T>::ReverseIterator List<T>::rend()
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
150 {
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
151 return _deque.rend();
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
152 }
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 template<typename T>
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
155 inline typename List<T>::ConstReverseIterator List<T>::crend() const
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
156 {
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
157 return _deque.crend();
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
158 }
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
159
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
160 template<typename T>
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
161 void List<T>::removeAt (int pos)
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
162 {
125
85814c0918c5 - now with a smarter assert
Teemu Piippo <crimsondusk64@gmail.com>
parents: 124
diff changeset
163 ASSERT_LT (pos, size());
124
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
164 _deque.erase (_deque.begin() + pos);
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
165 }
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
166
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
167 template<typename T>
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
168 inline T& List<T>::prepend (const T& value)
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
169 {
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
170 _deque.push_front (value);
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
171 return _deque[0];
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
172 }
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
173
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
174 template<typename T>
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
175 inline T& List<T>::append (const T& value)
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
176 {
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
177 _deque.push_back (value);
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
178 return _deque[_deque.size() - 1];
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
179 }
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
180
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
181 template<typename T>
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
182 void List<T>::merge (const List<T>& other)
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
183 {
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
184 resize (size() + other.size());
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
185 std::copy (other.begin(), other.end(), begin() + other.size());
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
186 }
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
187
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
188 template<typename T>
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
189 bool List<T>::pop (T& val)
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
190 {
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
191 if (isEmpty())
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
192 return false;
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 val = _deque[size() - 1];
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
195 _deque.erase (_deque.end() - 1);
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
196 return true;
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
197 }
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
198
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
199 template<typename T>
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
200 inline List<T>& List<T>::operator<< (const T& value)
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
201 {
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
202 append (value);
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
203 return *this;
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
204 }
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
205
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
206 template<typename T>
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
207 inline List<T>& List<T>::operator<< (const List<T>& vals)
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
208 {
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
209 merge (vals);
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
210 return *this;
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
211 }
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
212
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
213 template<typename T>
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
214 List<T> List<T>::reverse() const
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 List<T> rev;
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
217 std::copy (rbegin(), rend(), rev.begin());
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
218 return rev;
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
219 }
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 template<typename T>
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
222 inline void List<T>::clear()
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
223 {
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
224 _deque.clear();
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
225 }
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 template<typename T>
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
228 inline void List<T>::insert (int pos, const T& value)
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
229 {
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
230 _deque.insert (_deque.begin() + pos, value);
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
231 }
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
232
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
233 template<typename T>
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
234 void List<T>::removeDuplicates()
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
235 {
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
236 sort();
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
237 resize (std::distance (begin(), std::unique (begin(), end())));
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
238 }
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 template<typename T>
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
241 int List<T>::size() const
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
242 {
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
243 return _deque.size();
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
244 }
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
245
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
246 template<typename T>
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
247 inline T& List<T>::operator[] (int n)
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
248 {
125
85814c0918c5 - now with a smarter assert
Teemu Piippo <crimsondusk64@gmail.com>
parents: 124
diff changeset
249 ASSERT_LT (n, size());
124
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
250 return _deque[n];
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
251 }
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
252
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
253 template<typename T>
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
254 inline const T& List<T>::operator[] (int n) const
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
255 {
125
85814c0918c5 - now with a smarter assert
Teemu Piippo <crimsondusk64@gmail.com>
parents: 124
diff changeset
256 ASSERT_LT (n, size());
124
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
257 return _deque[n];
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
258 }
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 template<typename T>
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
261 inline void List<T>::resize (int size)
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
262 {
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
263 _deque.resize (size);
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
264 }
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 template<typename T>
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
267 inline void List<T>::sort()
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
268 {
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
269 std::sort (begin(), end());
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
270 }
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 template<typename T>
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
273 int List<T>::find (const T& needle) const
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 auto it = std::find (_deque.cbegin(), _deque.cend(), needle);
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 if (it == _deque.end())
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
278 return -1;
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
279
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
280 return it - _deque.cbegin();
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
281 }
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 template<typename T>
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
284 void List<T>::removeOne (const T& a)
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 auto it = std::find (_deque.begin(), _deque.end(), a);
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
287
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
288 if (it != _deque.end())
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
289 _deque.erase (it);
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
290 }
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 template<typename T>
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
293 inline bool List<T>::isEmpty() const
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
294 {
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
295 return size() == 0;
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
296 }
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
297
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
298 template<typename T>
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
299 List<T> List<T>::splice (int a, int b) const
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
300 {
125
85814c0918c5 - now with a smarter assert
Teemu Piippo <crimsondusk64@gmail.com>
parents: 124
diff changeset
301 ASSERT_RANGE (a, 0, size() - 1)
85814c0918c5 - now with a smarter assert
Teemu Piippo <crimsondusk64@gmail.com>
parents: 124
diff changeset
302 ASSERT_RANGE (b, 0, size() - 1)
85814c0918c5 - now with a smarter assert
Teemu Piippo <crimsondusk64@gmail.com>
parents: 124
diff changeset
303 ASSERT_LT_EQ (a, b)
124
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
304 List<T> 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 for (int i = a; i <= b; ++i)
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
307 result << operator[] (i);
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
308
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
309 return result;
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
310 }
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 template<typename T>
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
313 inline const std::deque<T>& List<T>::deque() const
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
314 {
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
315 return _deque;
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
316 }
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 template<typename T>
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
319 inline const T& List<T>::first() const
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
320 {
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
321 return *_deque.cbegin();
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
322 }
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 template<typename T>
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
325 inline const T& List<T>::last() const
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
326 {
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
327 return *(_deque.cend() - 1);
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
328 }
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 template<typename T>
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
331 inline bool List<T>::contains (const T& a) const
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
332 {
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
333 return std::find (_deque.cbegin(), _deque.cend(), a) != _deque.end();
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
334 }
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
335
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
336 template<typename T>
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
337 inline List<T> List<T>::operator+ (const List<T>& other) const
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
338 {
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
339 List<T> out (*this);
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
340 out.merge (other);
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
341 return out;
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
342 }
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
343
119
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
344 template<typename T>
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
345 List<T>& operator>> (const T& value, List<T>& haystack)
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
346 {
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
347 haystack.prepend (value);
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
348 return haystack;
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
349 }
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
350
124
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
351 #endif // BOTC_LIST_H

mercurial