Aleph-w 7.10.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 <type_traits>
49# include <ahDry.H>
50# include <ahIterator.H>
51# include <ah-args-ctor.H>
52# include <htlist.H>
53# include <tpl_dynDlist.H>
54#include <ah-iterator.H>
55
56namespace Aleph {
57
64 template <typename T>
66 : public LocateFunctions<DynListQueue<T>, T>,
67 public FunctionalMethods<DynListQueue<T>, T>,
68 public GenericKeys<DynListQueue<T>, T>,
69 public EqualSequenceMethod<DynListQueue<T>>,
70 public StlAlephIterator<DynListQueue<T>>
71{
73
75
76public:
77
79 void swap(DynListQueue & __q) noexcept
80 {
81 q.swap(__q.q);
82 }
83
85 DynListQueue() noexcept { /* empty */ }
86
88 DynListQueue(const DynListQueue & __q) : q(__q.q)
89 {
90 // empty
91 }
92
94 DynListQueue(DynListQueue && __q) noexcept
95 {
96 swap(__q);
97 }
98
100
103 {
104 if (this == &rhs)
105 return *this;
106
107 q = rhs.q;
108
109 return *this;
110 }
111
114 {
115 q.swap(rhs.q);
116 return *this;
117 }
118
120 [[nodiscard]] size_t size() const noexcept { return q.size(); }
121
123 [[nodiscard]] bool is_empty() const noexcept { return q.is_empty(); }
124
126
127 using Item_Type = T;
128
136 T & put(const T & data)
137 {
138 return q.append(data);
139 }
140
148 T & put(T && data)
149 {
150 return q.append(std::forward<T>(data));
151 }
152
153 T & append(const T & data) { return put(data); }
154
155 T & append(T && data)
156 {
157 return put(std::forward<T>(data));
158 }
159
160 T & insert(const T & data) { return put(data); }
161
162 T & insert(T && data)
163 {
164 return put(std::forward<T>(data));
165 }
166
176 template <typename... Args>
177 T & emplace(Args&&... args)
178 {
179 return put(T(std::forward<Args>(args)...));
180 }
181
183 T pop() { return get(); }
184
190 void clear() noexcept { empty(); }
191
201 {
202 return q.remove_first();
203 }
204
211 {
212 return q.get_first();
213 }
214
220 const T & front() const
221 {
222 return q.get_first();
223 }
224
230 T & rear()
231 {
232 return q.get_last();
233 }
234
240 const T & rear() const
241 {
242 return q.get_last();
243 }
244
246 void empty() noexcept
247 {
248 q.empty();
249 assert(q.is_empty());
250 }
251
259 template <class Operation>
261 bool traverse(Operation & operation)
262 noexcept(noexcept(q.traverse(operation)))
263 {
264 return q.traverse(operation);
265 }
266
268 template <class Operation>
270 bool traverse(Operation & operation) const
271 noexcept(noexcept(q.traverse(operation)))
272 {
273 return q.traverse(operation);
274 }
275
277 template <class Operation>
279 bool traverse(Operation && operation = Operation()) const
280 noexcept(noexcept(q.traverse(operation)))
281 {
282 return q.traverse(std::forward<Operation>(operation));
283 }
284
286 template <class Operation>
288 bool traverse(Operation && operation = Operation())
289 noexcept(noexcept(q.traverse(operation)))
290 {
291 return q.traverse(std::forward<Operation>(operation));
292 }
293
301 T * search(const T & key)
302 noexcept(noexcept(static_cast<bool>(std::declval<const T &>() == std::declval<const T &>())))
303 {
304 return this->find_ptr([&key](const T & item) { return static_cast<bool>(item == key); });
305 }
306
308 const T * search(const T & key) const
309 noexcept(noexcept(static_cast<bool>(std::declval<const T &>() == std::declval<const T &>())))
310 {
311 return this->find_ptr([&key](const T & item) { return static_cast<bool>(item == key); });
312 }
313
315 using Key_Type = T;
316
323 struct Iterator : public DynList<T>::Iterator
324 {
325 using Base = typename DynList<T>::Iterator;
326 using Base::Base;
327
329 Iterator(DynListQueue<T> & q) noexcept : Base(q.q) {}
330
332 Iterator(const DynListQueue<T> &) = delete;
333 };
334
337};
338
339} // end namespace Aleph
340# endif // TPL_DYNLISTQUEUE_H
341
Variadic constructor macros for containers.
STL-compatible iterator adapters for Aleph containers.
DRY (Don't Repeat Yourself) utilities and macros.
#define Special_Ctors(Set_Type, Type)
Generates special constructors for containers.
Definition ahDry.H:123
Iterator traits and STL-compatible iterator wrappers.
Read-only view of an Aleph iterator: the iterator of a constant container.
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.
DynListQueue(DynListQueue &&__q) noexcept
Construct in constant time a queue from __q
T Key_Type
Alias for the item type.
const T * search(const T &key) const noexcept(noexcept(static_cast< bool >(std::declval< const T & >()==std::declval< const T & >())))
See search(const T & key).
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=Operation()) noexcept(noexcept(q.traverse(operation)))
See traverse (Operation & operation).
bool traverse(Operation &operation) const noexcept(noexcept(q.traverse(operation)))
See traverse(Operation & operation).
void swap(DynListQueue &__q) noexcept
Swap this with __q in constant time.
void empty() noexcept
Empty the queue.
T * search(const T &key) noexcept(noexcept(static_cast< bool >(std::declval< const T & >()==std::declval< const T & >())))
Search for an item in the queue using equality comparison.
T & put(T &&data)
Put an item by moving.
T & front()
Return a modifiable reference to the oldest item in the queue.
void clear() noexcept
Empties the container.
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.
bool traverse(Operation &operation) noexcept(noexcept(q.traverse(operation)))
Traverse all the elements from the oldest (front) to the youngest (rear) and execute operation on eac...
size_t size() const noexcept
Return the number of elements.
bool traverse(Operation &&operation=Operation()) const noexcept(noexcept(q.traverse(operation)))
See traverse (Operation & operation).
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.
bool is_empty() const noexcept
Return true if this is empty.
Iterator on the items of list.
Definition htlist.H:1614
Doubly-linked list (defined in tpl_dynList.H).
Definition htlist.H:1231
T & get_first()
Return the first item of the list.
Definition htlist.H:1548
T & append(const T &item)
Definition htlist.H:1362
T & get_last()
Return the last item of the list.
Definition htlist.H:1529
T remove_first()
See remove().
Definition htlist.H:1473
size_t size() const noexcept
Return the number of items of the list, in constant time.
Definition htlist.H:1264
void empty() noexcept
empty the list
Definition htlist.H:1576
DynList & swap(DynList &l) noexcept
Definition htlist.H:1253
constexpr bool is_empty() const noexcept
Definition htlist.H:434
Mixin providing equality comparison for sequence containers.
Definition ah-dry.H:2945
Common methods to the Aleph-w ( ) containers.
Definition ah-dry.H:1235
Common sequential searching methods on containers.
Definition ah-dry.H:555
and Aleph::dry_detail::MutablyTraversable< typename Aleph::concepts_detail::defer< DynListQueue< T >, Operation >::type, T > T * find_ptr(Operation &operation) noexcept(mutable_search_is_noexcept< Operation >())
Find a pointer to an item in the container according to a searching criterion.
Definition ah-dry.H:825
Mixin that adds STL begin()/end() and cbegin()/cend() to Aleph containers.
f(args...) is a valid call whose result is usable as a condition.
Singly linked list implementations with head-tail access.
Main namespace for Aleph-w library functions.
std::decay_t< typename HeadC::Item_Type > T
Definition ah-zip.H:152
Iterator on elements of a queue.
typename DynList< T >::Iterator Base
Iterator(DynListQueue< T > &q) noexcept
Iterator on the modifiable queue q.
Iterator(const DynListQueue< T > &)=delete
A constant queue is iterated through Const_Iterator.
Generic list of items stored in a container.
Definition ah-dry.H:2896
bool traverse(Operation &operation) noexcept(traverse_is_noexcept< Operation, typename Aleph::concepts_detail::traverse_arg< Container, Operation >::type, Container & >())
Traverse the container via its iterator and performs a conditioned operation on each item.
Definition ah-dry.H:411
Dynamic doubly linked list implementation.