6 List<T>::List(Allocator* allocator) noexcept:
7 m_allocator(allocator),
15 List<T>::~List() noexcept
22 List<T>::List(
const List& rhs) noexcept:
23 m_allocator(rhs.m_allocator),
27 for (
auto it=rhs.cbegin(); it!= rhs.cend(); ++it)
34 List<T>& List<T>::operator=(
const List<T>& rhs) noexcept
36 for (
auto it = rhs.cbegin(); it != rhs.cend(); ++it)
44 List<T>::List(List&& rhs) noexcept:
47 m_allocator(rhs.m_allocator)
54 List<T>& List<T>::operator=(List<T>&& rhs) noexcept
58 m_allocator = rhs.m_allocator;
65 void List<T>::clear() noexcept
67 Node* _currNode = m_tail;
70 Node* prev = _currNode->_prev;
72 m_allocator->free(_currNode);
80 size_t List<T>::size() const noexcept
83 Node* _currNode = m_head;
87 _currNode = _currNode->_next;
93 size_t List<T>::length() const noexcept
107 return iterator(
nullptr);
111 typename List<T>::const_iterator List<T>::cbegin() const noexcept
113 return const_iterator(m_head);
117 typename List<T>::const_iterator List<T>::cend() const noexcept
119 return const_iterator(
nullptr);
123 typename List<T>::reverse_iterator List<T>::rbegin() noexcept
125 return reverse_iterator(m_tail);
129 typename List<T>::reverse_iterator List<T>::rend() noexcept
131 return reverse_iterator(
nullptr);
135 typename List<T>::const_reverse_iterator List<T>::crbegin() const noexcept
137 return const_reverse_iterator(m_tail);
141 typename List<T>::const_reverse_iterator List<T>::crend() const noexcept
143 return const_reverse_iterator(
nullptr);
159 T& List<T>::front() noexcept
165 const T& List<T>::front() const noexcept
173 Node* value =
static_cast<Node*
>(m_allocator->malloc(
sizeof(
Node)));
174 new (value)
Node(element);
182 m_tail->_next = value;
183 value->_prev = m_tail;
195 m_tail = node->_prev;
196 m_tail->_next =
nullptr;
204 m_allocator->free(node);
210 Node* value =
static_cast<Node*
>(m_allocator->malloc(
sizeof(
Node)));
211 new (value)
Node(element);
219 value->_next = m_head;
230 m_head = node->_next;
231 m_head->_prev =
nullptr;
239 m_allocator->free(node);
243 typename List<T>::iterator List<T>::insert(const_iterator pos,
const T& value) noexcept
245 if (pos == cend() || !pos.m_ptr)
return end();
246 Node* node =
const_cast<Node*
>(pos.m_ptr);
248 Node* new_node =
static_cast<Node*
>(m_allocator->malloc(
sizeof(Node)));
249 new (new_node) Node(value);
250 Node* prevNode = node->_prev;
251 node->_prev = new_node;
252 new_node->_next = node;
257 prevNode->_next = new_node;
258 new_node->_prev = prevNode;
260 return iterator(new_node);
264 typename List<T>::iterator List<T>::insert(iterator pos,
const T& value) noexcept
266 if (pos == end() || !pos.m_ptr)
return end();
267 Node* node = pos.m_ptr;
269 Node* new_node =
static_cast<Node*
>(m_allocator->malloc(
sizeof(Node)));
270 new (new_node) Node(value);
271 Node* prevNode = node->_prev;
272 node->_prev = new_node;
273 new_node->_next = node;
278 prevNode->_next = new_node;
279 new_node->_prev = prevNode;
281 return iterator(new_node);
285 typename List<T>::iterator List<T>::erase(const_iterator pos) noexcept
287 if (pos == cend() || !pos.m_ptr)
return end();
288 Node* node =
const_cast<Node*
>(pos.m_ptr);
289 Node* prev = node->_prev;
290 Node* next = node->_next;
293 m_allocator->free(node);
312 return iterator(next);
316 typename List<T>::iterator List<T>::erase(iterator pos) noexcept
318 if (pos == end() || !pos.m_ptr)
return end();
319 Node* node = pos.m_ptr;
320 Node* prev = node->_prev;
321 Node* next = node->_next;
324 m_allocator->free(node);
343 return iterator(next);
347 typename List<T>::iterator List<T>::find(
const T& element) noexcept
350 for (
auto it = begin(); it != end_it; ++it)
352 if (*it == element)
return it;
358 typename List<T>::const_iterator List<T>::find(
const T& element)
const noexcept
360 auto end_it = cend();
361 for (
auto it = cbegin(); it != end_it; ++it)
363 if (*it == element)
return it;