2 * Copyright (C) 2024-2026 David C. Manuelda (StormBytePP)
4 * This is the base for StormByte Suite libraries.
6 * StormByte original source is dual-licensed:
8 * 1. GNU Lesser General Public License v3.0 (or later)
9 * You may redistribute and/or modify this file under the terms of the
10 * GNU Lesser General Public License as published by the Free Software
11 * Foundation, either version 3 of the License, or (at your option)
14 * 2. Commercial license
15 * Alternatively, this file may be used under the terms of a commercial
16 * license agreement with the copyright holder
17 * (David C. Manuelda <StormByte@gmail.com>).
19 * Both licenses apply only to original StormByte source in this repository.
20 * They do not cover other StormByte modules or any third-party material
21 * shipped with this repository (including everything under thirdparty/),
22 * which remains under its own license.
24 * Neither license grants any patent rights. Any patent licenses required
25 * to use this software or third-party components must be obtained separately
26 * from the patent holders.
28 * StormByte is distributed in the hope that it will be useful,
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 * GNU Lesser General Public License for more details.
33 * You should have received a copy of the GNU Lesser General Public License
34 * version 3 along with StormByte. If not, see
35 * <https://www.gnu.org/licenses/lgpl-3.0.html>.
37 * SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-StormByte-Commercial
48 template<Type::SafeValue T>
49 Queue<T>::Queue() noexcept: m_values() {}
51 template<Type::SafeValue T>
52 Queue<T>::Queue(const container_type& values): m_values(values) {}
54 template<Type::SafeValue T>
55 Queue<T>::Queue(container_type&& values) noexcept: m_values(std::move(values)) {}
57 template<Type::SafeValue T>
58 Queue<T>::Queue(const Queue& other): m_values(other.m_values) {}
60 template<Type::SafeValue T>
61 Queue<T>::Queue(Queue&& other) noexcept: m_values(std::move(other.m_values)) {}
63 template<Type::SafeValue T>
64 Queue<T>::~Queue() noexcept = default;
66 template<Type::SafeValue T>
67 Queue<T>& Queue<T>::operator=(const Queue& other) {
70 m_values = other.m_values;
74 template<Type::SafeValue T>
75 Queue<T>& Queue<T>::operator=(Queue&& other) noexcept {
78 m_values = std::move(other.m_values);
82 template<Type::SafeValue T>
83 Queue<T>::iterator Queue<T>::begin() noexcept {
84 return m_values.begin();
87 template<Type::SafeValue T>
88 Queue<T>::iterator Queue<T>::end() noexcept {
89 return m_values.end();
92 template<Type::SafeValue T>
93 Queue<T>::const_iterator Queue<T>::begin() const noexcept {
94 return m_values.begin();
97 template<Type::SafeValue T>
98 Queue<T>::const_iterator Queue<T>::end() const noexcept {
99 return m_values.end();
102 template<Type::SafeValue T>
103 Queue<T>::const_iterator Queue<T>::cbegin() const noexcept {
104 return m_values.cbegin();
107 template<Type::SafeValue T>
108 Queue<T>::const_iterator Queue<T>::cend() const noexcept {
109 return m_values.cend();
112 template<Type::SafeValue T>
113 bool Queue<T>::empty() const noexcept {
114 return m_values.empty();
117 template<Type::SafeValue T>
118 Queue<T>::size_type Queue<T>::size() const noexcept {
119 return static_cast<size_type>(m_values.size());
122 template<Type::SafeValue T>
123 Queue<T>::reference Queue<T>::front() {
124 if (m_values.empty())
125 ThrowQueueOutOfBounds();
126 return m_values.front();
129 template<Type::SafeValue T>
130 Queue<T>::const_reference Queue<T>::front() const {
131 if (m_values.empty())
132 ThrowQueueOutOfBounds();
133 return m_values.front();
136 template<Type::SafeValue T>
137 Queue<T>::reference Queue<T>::back() {
138 if (m_values.empty())
139 ThrowQueueOutOfBounds();
140 return m_values.back();
143 template<Type::SafeValue T>
144 Queue<T>::const_reference Queue<T>::back() const {
145 if (m_values.empty())
146 ThrowQueueOutOfBounds();
147 return m_values.back();
150 template<Type::SafeValue T>
151 void Queue<T>::push(const T& value) {
152 if (m_values.size() == m_values.capacity()) {
154 m_values.push_back(std::move(stable));
156 m_values.push_back(value);
160 template<Type::SafeValue T>
161 void Queue<T>::push(T&& value) {
162 if (m_values.size() == m_values.capacity()) {
163 T stable(std::move(value));
164 m_values.push_back(std::move(stable));
166 m_values.push_back(std::move(value));
170 template<Type::SafeValue T>
171 template<class... Args>
172 Queue<T>::reference Queue<T>::emplace(Args&&... args) {
173 if (m_values.size() == m_values.capacity()) {
174 T stable(std::forward<Args>(args)...);
175 m_values.push_back(std::move(stable));
176 return m_values.back();
178 return m_values.emplace_back(std::forward<Args>(args)...);
181 template<Type::SafeValue T>
182 void Queue<T>::pop() {
183 if (m_values.empty())
184 ThrowQueueOutOfBounds();
185 m_values.erase(m_values.begin());
188 template<Type::SafeValue T>
189 Queue<T>::iterator Queue<T>::erase(const_iterator position) {
190 return m_values.erase(position);
193 template<Type::SafeValue T>
194 Queue<T>::iterator Queue<T>::erase(const_iterator first, const_iterator last) {
195 return m_values.erase(first, last);
198 template<Type::SafeValue T>
199 void Queue<T>::swap(Queue& other) noexcept {
200 m_values.swap(other.m_values);
203 template<Type::SafeValue T>
204 bool Queue<T>::operator==(const Queue& other) const requires Type::EqualityComparable<T> {
205 return m_values == other.m_values;
208 template<Type::SafeValue T>
209 STORMBYTE_FORCE_INLINE std::strong_ordering Queue<T>::operator<=>(const Queue& other) const requires std::three_way_comparable<T> {
210 return std::lexicographical_compare_three_way(begin(), end(), other.begin(), other.end());
213 template<Type::SafeValue T>
214 bool Queue<T>::operator<(const Queue& other) const requires requires(const T& left, const T& right) { left < right; } {
215 return m_values < other.m_values;
218 template<Type::SafeValue T>
219 bool Queue<T>::operator<=(const Queue& other) const requires requires(const T& left, const T& right) { left < right; } {
220 return m_values <= other.m_values;
223 template<Type::SafeValue T>
224 bool Queue<T>::operator>(const Queue& other) const requires requires(const T& left, const T& right) { left < right; } {
225 return m_values > other.m_values;
228 template<Type::SafeValue T>
229 bool Queue<T>::operator>=(const Queue& other) const requires requires(const T& left, const T& right) { left < right; } {
230 return m_values >= other.m_values;