FastLED 3.9.15
Loading...
Searching...
No Matches
queue.h
Go to the documentation of this file.
1#pragma once
2
3#include "fl/stl/deque.h"
4#include "fl/stl/move.h"
5#include "fl/stl/noexcept.h"
6namespace fl {
7
16template <typename T, typename Container = fl::deque<T>>
17class queue {
18public:
19 using value_type = T;
20 using size_type = fl::size;
21 using reference = T&;
22 using const_reference = const T&;
23 using container_type = Container;
24
25private:
26 Container mContainer;
27
28public:
30 queue() FL_NOEXCEPT = default;
31
34 explicit queue(const Container& container) : mContainer(container) {}
35
38 explicit queue(Container&& container) : mContainer(fl::move(container)) {}
39
42 queue(const queue& other) FL_NOEXCEPT = default;
43
46 queue(queue&& other) FL_NOEXCEPT = default;
47
51 queue& operator=(const queue& other) FL_NOEXCEPT = default;
52
56 queue& operator=(queue&& other) FL_NOEXCEPT = default;
57
59 ~queue() FL_NOEXCEPT = default;
60
65 return mContainer.front();
66 }
67
72 return mContainer.front();
73 }
74
79 return mContainer.back();
80 }
81
86 return mContainer.back();
87 }
88
91 bool empty() const {
92 return mContainer.empty();
93 }
94
97 size_type size() const {
98 return mContainer.size();
99 }
100
103 void push(const value_type& value) {
104 mContainer.push_back(value);
105 }
106
110 mContainer.push_back(fl::move(value));
111 }
112
116 template<typename... Args>
117 void emplace(Args&&... args) {
118 mContainer.emplace_back(fl::forward<Args>(args)...);
119 }
120
123 void pop() {
124 mContainer.pop_front();
125 }
126
129 void swap(queue& other) {
130 mContainer.swap(other.mContainer);
131 }
132
134 void clear() {
135 mContainer.clear();
136 }
137
140 Container& get_container() {
141 return mContainer;
142 }
143
146 const Container& get_container() const {
147 return mContainer;
148 }
149
153 bool operator==(const queue& other) const {
154 return mContainer == other.mContainer;
155 }
156
160 bool operator!=(const queue& other) const {
161 return mContainer != other.mContainer;
162 }
163
167 bool operator<(const queue& other) const {
168 return mContainer < other.mContainer;
169 }
170
174 bool operator<=(const queue& other) const {
175 return mContainer <= other.mContainer;
176 }
177
181 bool operator>(const queue& other) const {
182 return mContainer > other.mContainer;
183 }
184
188 bool operator>=(const queue& other) const {
189 return mContainer >= other.mContainer;
190 }
191};
192
198template <typename T, typename Container>
200 lhs.swap(rhs);
201}
202
204template <typename T, typename Container>
206 return lhs.get_container() == rhs.get_container();
207}
208
210template <typename T, typename Container>
212 return lhs.get_container() != rhs.get_container();
213}
214
216template <typename T, typename Container>
218 return lhs.get_container() < rhs.get_container();
219}
220
222template <typename T, typename Container>
224 return lhs.get_container() <= rhs.get_container();
225}
226
228template <typename T, typename Container>
230 return lhs.get_container() > rhs.get_container();
231}
232
234template <typename T, typename Container>
236 return lhs.get_container() >= rhs.get_container();
237}
238
239} // namespace fl
bool empty() const
Check if the queue is empty.
Definition queue.h:91
queue(queue &&other) FL_NOEXCEPT=default
Move constructor.
bool operator==(const queue &other) const
Equality comparison.
Definition queue.h:153
bool operator<(const queue &other) const
Less-than comparison (lexicographic)
Definition queue.h:167
~queue() FL_NOEXCEPT=default
Destructor.
void push(const value_type &value)
Add an element to the back of the queue.
Definition queue.h:103
queue & operator=(queue &&other) FL_NOEXCEPT=default
Move assignment operator.
void emplace(Args &&... args)
Construct and add an element to the back of the queue.
Definition queue.h:117
T value_type
Definition queue.h:19
void clear()
Remove all elements from the queue.
Definition queue.h:134
queue(Container &&container)
Construct queue by moving the given container.
Definition queue.h:38
fl::size size_type
Definition queue.h:20
const Container & get_container() const
Get access to the underlying container (const version)
Definition queue.h:146
queue & operator=(const queue &other) FL_NOEXCEPT=default
Copy assignment operator.
bool operator>=(const queue &other) const
Greater-than-or-equal comparison.
Definition queue.h:188
bool operator!=(const queue &other) const
Inequality comparison.
Definition queue.h:160
const_reference back() const
Access the last element (back of queue) - const version.
Definition queue.h:85
void swap(queue &other)
Swap the contents with another queue.
Definition queue.h:129
Container container_type
Definition queue.h:23
Container mContainer
Definition queue.h:26
Container & get_container()
Get access to the underlying container (for advanced use)
Definition queue.h:140
size_type size() const
Get the number of elements in the queue.
Definition queue.h:97
void pop()
Remove the front element from the queue.
Definition queue.h:123
queue(const queue &other) FL_NOEXCEPT=default
Copy constructor.
const T & const_reference
Definition queue.h:22
const_reference front() const
Access the first element (front of queue) - const version.
Definition queue.h:71
bool operator<=(const queue &other) const
Less-than-or-equal comparison.
Definition queue.h:174
void push(value_type &&value)
Add an element to the back of the queue (move version)
Definition queue.h:109
bool operator>(const queue &other) const
Greater-than comparison.
Definition queue.h:181
queue() FL_NOEXCEPT=default
Default constructor - creates an empty queue.
reference front()
Access the first element (front of queue)
Definition queue.h:64
T & reference
Definition queue.h:21
reference back()
Access the last element (back of queue)
Definition queue.h:78
A first-in, first-out (FIFO) queue container adapter.
Definition queue.h:17
constexpr T && forward(typename remove_reference< T >::type &t) FL_NOEXCEPT
Definition s16x16x4.h:234
constexpr remove_reference< T >::type && move(T &&t) FL_NOEXCEPT
Definition s16x16x4.h:28
constexpr remove_reference< T >::type && move(T &&t) FL_NOEXCEPT
Definition move.h:28
constexpr int type_rank< T >::value
FASTLED_FORCE_INLINE bool operator!=(const CRGB &lhs, const CRGB &rhs) FL_NOEXCEPT
Check if two CRGB objects do not have the same color data.
Definition crgb.h:739
void swap(array< T, N > &lhs, array< T, N > &rhs) FL_NOEXCEPT
Definition array.h:209
FASTLED_FORCE_INLINE bool operator<(const CRGB &lhs, const CRGB &rhs) FL_NOEXCEPT
Check if the sum of the color channels in one CRGB object is less than another.
Definition crgb.h:745
FASTLED_FORCE_INLINE bool operator==(const CRGB &lhs, const CRGB &rhs) FL_NOEXCEPT
Check if two CRGB objects have the same color data.
Definition crgb.h:733
FASTLED_FORCE_INLINE bool operator>(const CRGB &lhs, const CRGB &rhs) FL_NOEXCEPT
Check if the sum of the color channels in one CRGB object is greater than another.
Definition crgb.h:754
FASTLED_FORCE_INLINE bool operator<=(const CRGB &lhs, const CRGB &rhs) FL_NOEXCEPT
Check if the sum of the color channels in one CRGB object is less than or equal to another.
Definition crgb.h:772
FASTLED_FORCE_INLINE bool operator>=(const CRGB &lhs, const CRGB &rhs) FL_NOEXCEPT
Check if the sum of the color channels in one CRGB object is greater than or equal to another.
Definition crgb.h:763
Base definition for an LED controller.
Definition crgb.hpp:179
corkscrew_args args
Definition old.h:149
#define FL_NOEXCEPT