ORIGINAL
Loading...
Searching...
No Matches
deque.h
Go to the documentation of this file.
1#ifndef DEQUE_H
2#define DEQUE_H
3
10
11#include "chain.h"
12#include "containerAdapter.h"
13
14namespace original {
15
30 template <typename TYPE,
31 template <typename, typename> typename SERIAL = chain,
32 template <typename> typename ALLOC = allocator>
33 class deque final : public containerAdapter<TYPE, SERIAL, ALLOC> {
34 public:
35
43 explicit deque(const SERIAL<TYPE, ALLOC<TYPE>>& serial = SERIAL<TYPE, ALLOC<TYPE>>{});
44
51 deque(const std::initializer_list<TYPE>& lst);
52
58 deque(const deque& other);
59
65 deque& operator=(const deque& other);
66
73 deque(deque&& other) noexcept;
74
81 deque& operator=(deque&& other) noexcept;
82
88 void pushBegin(const TYPE &e);
89
95 void pushEnd(const TYPE &e);
96
103 TYPE popBegin();
104
111 TYPE popEnd();
112
118 TYPE head() const;
119
125 TYPE tail() const;
126
131 [[nodiscard]] std::string className() const override;
132 };
133}
134
135 template <typename TYPE,
136 template <typename, typename> typename SERIAL,
137 template <typename> typename ALLOC>
138 original::deque<TYPE, SERIAL, ALLOC>::deque(const SERIAL<TYPE, ALLOC<TYPE>>& serial)
139 : containerAdapter<TYPE, SERIAL, ALLOC>(serial) {}
140
141 template <typename TYPE,
142 template <typename, typename> typename SERIAL,
143 template <typename> typename ALLOC>
144 original::deque<TYPE, SERIAL, ALLOC>::deque(const std::initializer_list<TYPE> &lst)
145 : deque(SERIAL<TYPE, ALLOC<TYPE>>(lst)) {}
146
147 template <typename TYPE,
148 template <typename, typename> typename SERIAL,
149 template <typename> typename ALLOC>
151 this->operator=(other);
152 }
153
154 template <typename TYPE,
155 template <typename, typename> typename SERIAL,
156 template <typename> typename ALLOC>
158 if (this == &other) return *this;
159 this->serial_ = other.serial_;
160 return *this;
161 }
162
163 template <typename TYPE,
164 template <typename, typename> typename SERIAL,
165 template <typename> typename ALLOC>
167 {
168 this->operator=(std::move(other));
169 }
170
171 template <typename TYPE,
172 template <typename, typename> typename SERIAL,
173 template <typename> typename ALLOC>
175 {
176 if (this == &other)
177 return *this;
178
179 this->serial_ = std::move(other.serial_);
180 return *this;
181 }
182
183 template <typename TYPE,
184 template <typename, typename> typename SERIAL,
185 template <typename> typename ALLOC>
187 this->serial_.pushBegin(e);
188 }
189
190 template <typename TYPE,
191 template <typename, typename> typename SERIAL,
192 template <typename> typename ALLOC>
194 this->serial_.pushEnd(e);
195 }
196
197 template <typename TYPE,
198 template <typename, typename> typename SERIAL,
199 template <typename> typename ALLOC>
201 return this->serial_.popBegin();
202 }
203
204 template <typename TYPE,
205 template <typename, typename> typename SERIAL,
206 template <typename> typename ALLOC>
208 return this->serial_.popEnd();
209 }
210
211 template <typename TYPE,
212 template <typename, typename> typename SERIAL,
213 template <typename> typename ALLOC>
215 return this->serial_.getBegin();
216 }
217
218 template <typename TYPE,
219 template <typename, typename> typename SERIAL,
220 template <typename> typename ALLOC>
222 return this->serial_.getEnd();
223 }
224
225 template <typename TYPE,
226 template <typename, typename> typename SERIAL,
227 template <typename> typename ALLOC>
229 return "deque";
230 }
231
232#endif //DEQUE_H
Non-cyclic doubly linked list implementation.
Default memory allocator using allocators utilities.
Definition allocator.h:154
Non-cyclic doubly linked list container.
Definition chain.h:36
chain< TYPE, allocator< TYPE > > serial_
Definition containerAdapter.h:60
containerAdapter(const chain< TYPE, allocator< TYPE > > &serial)
Definition containerAdapter.h:139
TYPE popBegin()
Removes and returns front element.
Definition deque.h:200
deque(const SERIAL< TYPE, ALLOC< TYPE > > &serial=SERIAL< TYPE, ALLOC< TYPE > >{})
Constructs deque with specified underlying container and allocator.
Definition deque.h:138
std::string className() const override
Gets class name identifier.
Definition deque.h:228
TYPE tail() const
Accesses back element.
Definition deque.h:221
deque & operator=(const deque &other)
Copy assignment operator.
Definition deque.h:157
void pushBegin(const TYPE &e)
Inserts element at the front.
Definition deque.h:186
TYPE popEnd()
Removes and returns back element.
Definition deque.h:207
TYPE head() const
Accesses front element.
Definition deque.h:214
void pushEnd(const TYPE &e)
Inserts element at the back.
Definition deque.h:193
Abstract base class for sequential containers with index-based access.
Definition serial.h:34
Base class for container adapters with common interfaces.
Main namespace for the project Original.
Definition algorithms.h:21