Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
Deque.h
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4#ifndef _Stroika_Foundation_Containers_Deque_h_
5#define _Stroika_Foundation_Containers_Deque_h_ 1
6
7#include "Stroika/Foundation/StroikaPreComp.h"
8
10
11/*
12 *
13 * \note Code-Status: <a href="Code-Status.md#Beta">Beta</a>
14 *
15 */
16
18
20 using Traversal::IInputIterator;
21 using Traversal::IIterableOfTo;
22 using Traversal::Iterable;
23 using Traversal::Iterator;
24
25 /**
26 * Description:
27 *
28 * A Deque is a Queue that allows additions and removals at either end.
29 *
30 * Deques - like Queues - iterate from Head to Tail.
31 *
32 * Notes:
33 *
34 * <<NOTE - FUTURE WORK - AND DON'T DOCUMENT DEFAULTIMPL HERE>>> - SEE FACTORY CODE
35 * We currently default to the circular array implementation, as it is
36 * fastest under most circumstances. One drawback to it is that it has
37 * unpredictable costs for an Add operation. DoubleLinkList is usually
38 * slower, but has very predictable costs.
39 *
40 * \em Concrete Implementations:
41 * o @see Concrete::Deque_DoublyLinkedList<>
42 *
43 * \em Factory:
44 * @see Deque_Factory<> to see default implementations.
45 *
46 * \note \em Thread-Safety <a href="Thread-Safety.md#C++-Standard-Thread-Safety">C++-Standard-Thread-Safety</a>
47 *
48 * \note See <a href="./ReadMe.md">ReadMe.md</a> for common features of all Stroika containers (especially
49 * constructors, iterators, etc)
50 *
51 * \note <a href="Design-Overview.md#Comparisons">Comparisons</a>:
52 * @see inherited from Queue<T>
53 */
54 template <typename T>
55 class [[nodiscard]] Deque : public Queue<T> {
56 private:
57 using inherited = Queue<T>;
58
59 public:
60 /**
61 * Use this typedef in templates to recover the basic functional container pattern of concrete types.
62 */
64
65 public:
66 /**
67 * @see inherited::value_type
68 */
70
71 protected:
72 class _IRep;
73
74 public:
75 /**
76 * \note <a href="ReadMe.md#Container Constructors">See general information about container constructors that applies here</a>
77 */
78 Deque ();
79 Deque (Deque&&) noexcept = default;
80 Deque (const Deque&) noexcept = default;
81 Deque (const initializer_list<value_type>& src);
82 template <IIterableOfTo<T> ITERABLE_OF_ADDABLE>
83 explicit Deque (ITERABLE_OF_ADDABLE&& src)
84 requires (not derived_from<remove_cvref_t<ITERABLE_OF_ADDABLE>, Deque<T>>)
85#if qCompilerAndStdLib_RequiresNotMatchInlineOutOfLineForTemplateClassBeingDefined_Buggy
86 : Deque{}
87 {
88 this->AddAllToTail (forward<ITERABLE_OF_ADDABLE> (src));
89 _AssertRepValidType ();
90 }
91#endif
92 ;
93 template <IInputIterator<T> ITERATOR_OF_ADDABLE>
94 Deque (ITERATOR_OF_ADDABLE&& start, ITERATOR_OF_ADDABLE&& end);
95
96 protected:
97 /**
98 */
99 explicit Deque (shared_ptr<_IRep>&& src) noexcept;
100 explicit Deque (const shared_ptr<_IRep>& src) noexcept;
101
102 public:
103 /**
104 */
105 nonvirtual Deque& operator= (Deque&&) noexcept = default;
106 nonvirtual Deque& operator= (const Deque&) = default;
107
108 public:
109 /**
110 * \note mutates container
111 */
112 nonvirtual void AddHead (ArgByValueType<value_type> item);
113
114 public:
115 /**
116 * @aliases AddHead
117 */
118 nonvirtual void push_front (ArgByValueType<value_type> item);
119
120 public:
121 /**
122 * \note mutates container
123 */
124 nonvirtual value_type RemoveTail ();
125
126 public:
127 /**
128 * @aliases RemoveTail
129 */
130 nonvirtual T pop_back ();
131
132 public:
133 /**
134 */
135 nonvirtual value_type Tail () const;
136
137 public:
138 /**
139 * @aliases Tail
140 * \pre not empty ()
141 */
142 nonvirtual T back () const;
143
144 protected:
145 /**
146 */
147 template <typename T2>
148 using _SafeReadRepAccessor = typename inherited::template _SafeReadRepAccessor<T2>;
149
150 protected:
151 /**
152 */
153 template <typename T2>
154 using _SafeReadWriteRepAccessor = typename inherited::template _SafeReadWriteRepAccessor<T2>;
155
156 protected:
157 nonvirtual void _AssertRepValidType () const;
158 };
159
160 /**
161 * \brief Implementation detail for Deque<T> implementors.
162 *
163 * Protected abstract interface to support concrete implementations of
164 * the Deque<T> container API.
165 */
166 template <typename T>
167 class Deque<T>::_IRep : public Queue<T>::_IRep {
168 private:
169 using inherited = typename Queue<T>::_IRep;
170
171 public:
172 virtual void AddHead (ArgByValueType<value_type> item) = 0;
173 virtual value_type RemoveTail () = 0;
174 virtual value_type Tail () const = 0;
175 };
176
177}
178
179/*
180 ********************************************************************************
181 ******************************* Implementation Details *************************
182 ********************************************************************************
183 */
184
185#include "Deque.inl"
186
187#endif /*_Stroika_Foundation_Containers_Deque_h_ */
Implementation detail for Deque<T> implementors.
Definition Deque.h:167
typename inherited::value_type value_type
Definition Deque.h:69
Implementation detail for Queue<T> implementors.
Definition Queue.h:306
A Queue is a first-in-first-out (FIFO) data structure, where elements are arranged in well-ordered fa...
Definition Queue.h:95
typename inherited::value_type value_type
Definition Queue.h:109
conditional_t<(sizeof(CHECK_T)<=2 *sizeof(void *)) and is_trivially_copyable_v< CHECK_T >, CHECK_T, const CHECK_T & > ArgByValueType
This is an alias for 'T' - but how we want to pass it on stack as formal parameter.
Definition TypeHints.h:32