Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
tpl_dynListQueue.H
Go to the documentation of this file.
1
2/*
3 Aleph_w
4
5 Data structures & Algorithms
6 version 2.0.0b
7 https://github.com/lrleon/Aleph-w
8
9 This file is part of Aleph-w library
10
11 Copyright (c) 2002-2026 Leandro Rabindranath Leon
12
13 Permission is hereby granted, free of charge, to any person obtaining a copy
14 of this software and associated documentation files (the "Software"), to deal
15 in the Software without restriction, including without limitation the rights
16 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17 copies of the Software, and to permit persons to whom the Software is
18 furnished to do so, subject to the following conditions:
19
20 The above copyright notice and this permission notice shall be included in all
21 copies or substantial portions of the Software.
22
23 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 SOFTWARE.
30*/
31
32
44# ifndef TPL_DYNLISTQUEUE_H
45# define TPL_DYNLISTQUEUE_H
46
47# include <iostream>
48# include <ahDry.H>
49# include <ahIterator.H>
50# include <ah-args-ctor.H>
51# include <htlist.H>
52# include <tpl_dynDlist.H>
53
54namespace Aleph {
55
62 template <typename T>
64 : public LocateFunctions<DynListQueue<T>, T>,
65 public FunctionalMethods<DynListQueue<T>, T>,
66 public GenericKeys<DynListQueue<T>, T>,
67 public EqualToMethod<DynListQueue<T>>,
68 public StlAlephIterator<DynListQueue<T>>
69{
71 size_t num_items = 0;
72
74
75public:
76
78 void swap(DynListQueue & __q) noexcept
79 {
80 std::swap(num_items, __q.num_items);
81 q.swap(__q.q);
82 }
83
85 DynListQueue() noexcept : num_items(0) { /* empty */ }
86
89 {
90 // empty
91 }
92
95 {
96 swap(__q);
97 }
98
100
103 {
104 if (this == &rhs)
105 return *this;
106
107 q = rhs.q;
108 num_items = rhs.num_items;
109
110 return *this;
111 }
112
115 {
116 std::swap(num_items, rhs.num_items);
117 q.swap(rhs.q);
118 return *this;
119 }
120
122 [[nodiscard]] constexpr size_t size() const noexcept { return num_items; }
123
125 [[nodiscard]] bool is_empty() const noexcept { return q.is_empty(); }
126
128
129 using Item_Type = T;
130
138 T & put(const T & data)
139 {
140 T & ret_val = q.append(data);
141 ++num_items;
142 return ret_val;
143 }
144
152 T & put(T && data)
153 {
154 T & ret_val = q.append(std::forward<T>(data));
155 ++num_items;
156 return ret_val;
157 }
158
159 T & append(const T & data) { return put(data); }
160
161 T & append(T && data)
162 {
163 return put(std::forward<T>(data));
164 }
165
166 T & insert(const T & data) { return put(data); }
167
168 T & insert(T && data)
169 {
170 return put(std::forward<T>(data));
171 }
172
182 template <typename... Args>
184 {
185 return put(T(std::forward<Args>(args)...));
186 }
187
189 T pop() { return get(); }
190
192 void clear() noexcept { empty(); }
193
200 {
202 --num_items;
203 return ret_val;
204 }
205
212 {
213 return q.get_first();
214 }
215
221 const T & front() const
222 {
223 return q.get_first();
224 }
225
231 T & rear()
232 {
233 return q.get_last();
234 }
235
241 const T & rear() const
242 {
243 return q.get_last();
244 }
245
248 {
249 q.empty();
250 num_items = 0;
251 assert(q.is_empty());
252 }
253
261 template <class Operation>
263 {
264 return q.traverse(operation);
265 }
266
268 template <class Operation>
270 {
271 return q.traverse(operation);
272 }
273
275 template <class Operation>
277 {
278 return q.traverse(std::forward<Operation>(operation));
279 }
280
282 template <class Operation>
284 {
285 return q.traverse(std::forward<Operation>(operation));
286 }
287
296 T * search(const T & key) noexcept
297 {
298 return this->find_ptr([&key](const T & item) { return item == key; });
299 }
300
302 const T * search(const T & key) const noexcept
303 {
304 return const_cast<DynListQueue*>(this)->search(key);
305 }
306
308 using Key_Type = T;
309
316 struct Iterator : public DynList<T>::Iterator
317 {
318 using Base = typename DynList<T>::Iterator;
319 using Base::Base;
320
322 };
323};
324
325} // end namespace Aleph
326# endif // TPL_DYNLISTQUEUE_H
327
Variadic constructor macros for containers.
DRY (Don't Repeat Yourself) utilities and macros.
#define Special_Ctors(Set_Type, Type)
Generates special constructors for containers.
Definition ahDry.H:113
Iterator traits and STL-compatible iterator wrappers.
Dynamic queue of elements of generic type T based on single linked list.
const T & front() const
Return a const reference to the oldest item in the queue.
DynListQueue & operator=(const DynListQueue &rhs)
Assign to this a copy of rhs
T & put(const T &data)
The type of element.
bool traverse(Operation &&operation=Operation()) const
DynListQueue(DynListQueue &&__q) noexcept
Construct in constant time a queue from __q
T Key_Type
Key_Type is required by EqualToMethod mixin.
constexpr size_t size() const noexcept
Return the number of elements.
T get()
Remove the oldest item of the queue.
const T & rear() const
Return a const reference to the youngest item in the queue.
bool traverse(Operation &operation) const
void swap(DynListQueue &__q) noexcept
Swap this with __q in constant time.
void empty() noexcept
Empty the queue.
T & put(T &&data)
Put an item by moving.
T & front()
Return a modifiable reference to the oldest item in the queue.
const T * search(const T &key) const noexcept
bool traverse(Operation &&operation=Operation())
bool traverse(Operation &operation)
Traverse all the elements from the oldest (front) to the youngest (rear) and execute operation on eac...
void clear() noexcept
Alias for empty() - clears all items from the queue.
T pop()
Alias for get() - removes and returns the front item.
T & insert(const T &data)
T & append(const T &data)
T & emplace(Args &&... args)
Construct an item in place at the rear of the queue.
DynListQueue() noexcept
Construct an empty queue.
DynListQueue(const DynListQueue &__q)
Construct a copy of __q
T Item_Type
The type of set.
T & rear()
Return a modifiable reference to the youngest item in the queue.
T * search(const T &key) noexcept
Search for an item in the queue using equality comparison.
bool is_empty() const noexcept
Return true if this is empty.
Iterator on the items of list.
Definition htlist.H:1714
Dynamic singly linked list with functional programming support.
Definition htlist.H:1423
T & append(const T &item)
Append a new item by copy.
Definition htlist.H:1562
T & get_last() const
Return the last item of the list.
Definition htlist.H:1663
T & get_first() const
Return the first item of the list.
Definition htlist.H:1675
void empty() noexcept
empty the list
Definition htlist.H:1689
DynList & swap(DynList &l) noexcept
Swap this with l.
Definition htlist.H:1448
constexpr bool is_empty() const noexcept
Return true if list is empty.
Definition htlist.H:523
Equality test for containers.
Definition ah-dry.H:1534
Common methods to the Aleph-w ( ) containers.
Definition ah-dry.H:548
Aleph::DynList< __T > maps(Operation &op) const
Map the elements of the container.
Definition ah-dry.H:904
Common sequential searching methods on containers.
Definition ah-dry.H:164
T * find_ptr(Operation &operation) noexcept(operation_is_noexcept< Operation >())
Find a pointer to an item in the container according to a searching criteria.
Definition ah-dry.H:318
Mixin that adds STL begin()/end() and cbegin()/cend() to Aleph containers.
Singly linked list implementations with head-tail access.
Main namespace for Aleph-w library functions.
Definition ah-arena.H:89
std::decay_t< typename HeadC::Item_Type > T
Definition ah-zip.H:107
Iterator on elements of a queue.
typename DynList< T >::Iterator Base
Iterator(const DynListQueue< T > &q) noexcept
Generic list of items stored in a container.
Definition ah-dry.H:1501
bool traverse(Operation &operation) noexcept(traverse_is_noexcept< Operation >())
Traverse the container via its iterator and performs a conditioned operation on each item.
Definition ah-dry.H:95
Dynamic doubly linked list implementation.