src/list.h

Thu, 24 Jul 2014 17:01:23 +0300

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Thu, 24 Jul 2014 17:01:23 +0300
changeset 142
1f5518dd8146
parent 139
cf11621ae422
permissions
-rw-r--r--

- and --help works now correctly too

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>
139
cf11621ae422 - added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents: 135
diff changeset
36 #include <functional>
119
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
37
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
38 template<typename T>
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
39 class List
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
40 {
124
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
41 public:
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
42 using Iterator = typename std::deque<T>::iterator;
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
43 using ConstIterator = typename std::deque<T>::const_iterator;
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
44 using ReverseIterator = typename std::deque<T>::reverse_iterator;
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
45 using ConstReverseIterator = typename std::deque<T>::const_reverse_iterator;
119
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
46
124
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
47 List();
135
8b9132fea327 - massive refactoring continues (doesn't compile yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 134
diff changeset
48 List (std::size_t numvalues);
124
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
49 List (const std::deque<T>& a);
135
8b9132fea327 - massive refactoring continues (doesn't compile yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 134
diff changeset
50 List (std::initializer_list<T>&& a);
119
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
51
124
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
52 inline T& append (const T& value);
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
53 inline Iterator begin();
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
54 inline ConstIterator begin() const;
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
55 inline void clear();
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
56 inline bool contains (const T& a) const;
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
57 inline ConstReverseIterator crbegin() const;
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
58 inline ConstReverseIterator crend() const;
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
59 inline const std::deque<T>& deque() const;
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
60 inline Iterator end();
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
61 inline ConstIterator end() const;
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
62 int find (const T& needle) const;
139
cf11621ae422 - added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents: 135
diff changeset
63 T* find (std::function<bool (T const&)> func);
cf11621ae422 - added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents: 135
diff changeset
64 T const* find (std::function<bool (T const&)> func) const;
124
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
65 inline const T& first() const;
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
66 inline void insert (int pos, const T& value);
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
67 inline bool isEmpty() const;
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
68 inline const T& last() const;
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
69 void merge (const List<T>& other);
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
70 bool pop (T& val);
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
71 inline T& prepend (const T& value);
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
72 inline ReverseIterator rbegin();
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
73 inline void removeAt (int pos);
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
74 void removeDuplicates();
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
75 void removeOne (const T& it);
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
76 inline ReverseIterator rend();
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
77 inline void resize (int size);
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
78 List<T> reverse() const;
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
79 inline int size() const;
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
80 inline void sort();
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
81 List<T> splice (int a, int b) const;
119
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
82
124
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
83 inline List<T>& operator<< (const T& value);
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
84 inline List<T>& operator<< (const List<T>& vals);
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
85 inline T& operator[] (int n);
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
86 inline const T& operator[] (int n) const;
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
87 inline List<T> operator+ (const List<T>& other) const;
119
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 private:
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
90 std::deque<T> _deque;
119
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
91 };
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
92
124
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
93 template<typename T>
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
94 List<T>& operator>> (const T& value, List<T>& haystack);
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 //
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
97 // --- IMPLEMENTATIONS
119
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
98 //
124
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() {}
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>
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
104 List<T>::List (const std::deque<T>& other) :
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
105 _deque (other) {}
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>
135
8b9132fea327 - massive refactoring continues (doesn't compile yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 134
diff changeset
108 List<T>::List (std::initializer_list< T > && a) :
124
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
109 _deque (a) {}
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
110
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
111 template<typename T>
135
8b9132fea327 - massive refactoring continues (doesn't compile yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 134
diff changeset
112 List<T>::List (std::size_t numvalues) :
8b9132fea327 - massive refactoring continues (doesn't compile yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 134
diff changeset
113 _deque (numvalues) {}
8b9132fea327 - massive refactoring continues (doesn't compile yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 134
diff changeset
114
8b9132fea327 - massive refactoring continues (doesn't compile yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 134
diff changeset
115 template<typename T>
124
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
116 inline typename List<T>::Iterator List<T>::begin()
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 return _deque.begin();
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
119 }
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 template<typename T>
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
122 inline typename List<T>::ConstIterator List<T>::begin() const
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 return _deque.cbegin();
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
125 }
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 template<typename T>
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
128 inline typename List<T>::Iterator List<T>::end()
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 return _deque.end();
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
131 }
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 template<typename T>
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
134 inline typename List<T>::ConstIterator List<T>::end() const
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 return _deque.cend();
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
137 }
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 template<typename T>
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
140 inline typename List<T>::ReverseIterator List<T>::rbegin()
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 return _deque.rbegin();
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
143 }
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 template<typename T>
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
146 inline typename List<T>::ConstReverseIterator List<T>::crbegin() const
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 return _deque.crbegin();
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
149 }
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 template<typename T>
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
152 inline typename List<T>::ReverseIterator List<T>::rend()
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 return _deque.rend();
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
155 }
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 template<typename T>
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
158 inline typename List<T>::ConstReverseIterator List<T>::crend() const
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 return _deque.crend();
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
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
163 template<typename T>
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
164 void List<T>::removeAt (int pos)
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
165 {
125
85814c0918c5 - now with a smarter assert
Teemu Piippo <crimsondusk64@gmail.com>
parents: 124
diff changeset
166 ASSERT_LT (pos, size());
124
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
167 _deque.erase (_deque.begin() + pos);
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
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
170 template<typename T>
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
171 inline T& List<T>::prepend (const T& value)
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 _deque.push_front (value);
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
174 return _deque[0];
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
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
177 template<typename T>
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
178 inline T& List<T>::append (const T& value)
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 _deque.push_back (value);
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
181 return _deque[_deque.size() - 1];
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
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
184 template<typename T>
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
185 void List<T>::merge (const List<T>& other)
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
186 {
142
1f5518dd8146 - and --help works now correctly too
Teemu Piippo <crimsondusk64@gmail.com>
parents: 139
diff changeset
187 int oldsize = size();
124
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
188 resize (size() + other.size());
142
1f5518dd8146 - and --help works now correctly too
Teemu Piippo <crimsondusk64@gmail.com>
parents: 139
diff changeset
189 std::copy (other.begin(), other.end(), begin() + oldsize);
124
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
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
192 template<typename T>
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
193 bool List<T>::pop (T& val)
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
194 {
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
195 if (isEmpty())
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
196 return false;
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 val = _deque[size() - 1];
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
199 _deque.erase (_deque.end() - 1);
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
200 return true;
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
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
203 template<typename T>
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
204 inline List<T>& List<T>::operator<< (const T& value)
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 append (value);
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
207 return *this;
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
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
210 template<typename T>
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
211 inline List<T>& List<T>::operator<< (const List<T>& vals)
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 merge (vals);
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
214 return *this;
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
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
217 template<typename T>
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
218 List<T> List<T>::reverse() const
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 List<T> rev;
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
221 std::copy (rbegin(), rend(), rev.begin());
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
222 return rev;
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
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
225 template<typename T>
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
226 inline void List<T>::clear()
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 _deque.clear();
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
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
231 template<typename T>
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
232 inline void List<T>::insert (int pos, const T& value)
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 _deque.insert (_deque.begin() + pos, value);
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
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
237 template<typename T>
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
238 void List<T>::removeDuplicates()
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 sort();
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
241 resize (std::distance (begin(), std::unique (begin(), end())));
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
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
244 template<typename T>
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
245 int List<T>::size() const
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 return _deque.size();
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
248 }
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
249
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
250 template<typename T>
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
251 inline T& List<T>::operator[] (int n)
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
252 {
125
85814c0918c5 - now with a smarter assert
Teemu Piippo <crimsondusk64@gmail.com>
parents: 124
diff changeset
253 ASSERT_LT (n, size());
124
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
254 return _deque[n];
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
255 }
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
256
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
257 template<typename T>
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
258 inline const T& List<T>::operator[] (int n) const
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
259 {
125
85814c0918c5 - now with a smarter assert
Teemu Piippo <crimsondusk64@gmail.com>
parents: 124
diff changeset
260 ASSERT_LT (n, size());
124
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
261 return _deque[n];
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
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
264 template<typename T>
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
265 inline void List<T>::resize (int size)
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 _deque.resize (size);
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
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
270 template<typename T>
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
271 inline void List<T>::sort()
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
272 {
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
273 std::sort (begin(), end());
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
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
276 template<typename T>
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
277 int List<T>::find (const T& needle) const
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
278 {
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
279 auto it = std::find (_deque.cbegin(), _deque.cend(), needle);
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 if (it == _deque.end())
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
282 return -1;
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
283
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
284 return it - _deque.cbegin();
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>
139
cf11621ae422 - added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents: 135
diff changeset
288 T* List<T>::find (std::function<bool (T const&)> func)
cf11621ae422 - added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents: 135
diff changeset
289 {
cf11621ae422 - added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents: 135
diff changeset
290 for (T& element : _deque)
cf11621ae422 - added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents: 135
diff changeset
291 {
cf11621ae422 - added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents: 135
diff changeset
292 if (func (element))
cf11621ae422 - added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents: 135
diff changeset
293 return &element;
cf11621ae422 - added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents: 135
diff changeset
294 }
cf11621ae422 - added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents: 135
diff changeset
295
cf11621ae422 - added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents: 135
diff changeset
296 return nullptr;
cf11621ae422 - added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents: 135
diff changeset
297 }
cf11621ae422 - added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents: 135
diff changeset
298
cf11621ae422 - added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents: 135
diff changeset
299 template<typename T>
cf11621ae422 - added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents: 135
diff changeset
300 T const* List<T>::find (std::function<bool (T const&)> func) const
cf11621ae422 - added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents: 135
diff changeset
301 {
cf11621ae422 - added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents: 135
diff changeset
302 for (T const& element : _deque)
cf11621ae422 - added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents: 135
diff changeset
303 {
cf11621ae422 - added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents: 135
diff changeset
304 if (func (element))
cf11621ae422 - added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents: 135
diff changeset
305 return &element;
cf11621ae422 - added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents: 135
diff changeset
306 }
cf11621ae422 - added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents: 135
diff changeset
307
cf11621ae422 - added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents: 135
diff changeset
308 return nullptr;
cf11621ae422 - added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents: 135
diff changeset
309 }
cf11621ae422 - added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents: 135
diff changeset
310
cf11621ae422 - added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents: 135
diff changeset
311 template<typename T>
124
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
312 void List<T>::removeOne (const T& a)
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
313 {
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
314 auto it = std::find (_deque.begin(), _deque.end(), a);
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 if (it != _deque.end())
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
317 _deque.erase (it);
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
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
320 template<typename T>
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
321 inline bool List<T>::isEmpty() const
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 return size() == 0;
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
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
326 template<typename T>
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
327 List<T> List<T>::splice (int a, int b) const
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
328 {
125
85814c0918c5 - now with a smarter assert
Teemu Piippo <crimsondusk64@gmail.com>
parents: 124
diff changeset
329 ASSERT_RANGE (a, 0, size() - 1)
85814c0918c5 - now with a smarter assert
Teemu Piippo <crimsondusk64@gmail.com>
parents: 124
diff changeset
330 ASSERT_RANGE (b, 0, size() - 1)
85814c0918c5 - now with a smarter assert
Teemu Piippo <crimsondusk64@gmail.com>
parents: 124
diff changeset
331 ASSERT_LT_EQ (a, b)
124
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
332 List<T> result;
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 for (int i = a; i <= b; ++i)
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
335 result << operator[] (i);
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
336
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
337 return result;
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
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
340 template<typename T>
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
341 inline const std::deque<T>& List<T>::deque() const
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 return _deque;
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
344 }
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
345
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
346 template<typename T>
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
347 inline const T& List<T>::first() const
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
348 {
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
349 return *_deque.cbegin();
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
350 }
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
351
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
352 template<typename T>
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
353 inline const T& List<T>::last() const
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
354 {
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
355 return *(_deque.cend() - 1);
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
356 }
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
357
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
358 template<typename T>
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
359 inline bool List<T>::contains (const T& a) const
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
360 {
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
361 return std::find (_deque.cbegin(), _deque.cend(), a) != _deque.end();
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
362 }
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
363
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
364 template<typename T>
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
365 inline List<T> List<T>::operator+ (const List<T>& other) const
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
366 {
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
367 List<T> out (*this);
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
368 out.merge (other);
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
369 return out;
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
370 }
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
371
119
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
372 template<typename T>
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
373 List<T>& operator>> (const T& value, List<T>& haystack)
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
374 {
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
375 haystack.prepend (value);
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
376 return haystack;
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
377 }
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
378
124
a7b769a0e537 - commence refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
379 #endif // BOTC_LIST_H

mercurial