FastLED 3.9.15
Loading...
Searching...
No Matches
queue.h
Go to the documentation of this file.
1#pragma once
2
3#include "fl/deque.h"
4#include "fl/move.h"
5#include "fl/namespace.h"
6
7namespace fl {
8
17template <typename T, typename Container = fl::deque<T>>
18class queue {
19public:
20 using value_type = T;
21 using size_type = fl::size;
22 using reference = T&;
23 using const_reference = const T&;
24 using container_type = Container;
25
26private:
27 Container mContainer;
28
29public:
31 queue() = default;
32
35 explicit queue(const Container& container) : mContainer(container) {}
36
39 explicit queue(Container&& container) : mContainer(fl::move(container)) {}
40
43 queue(const queue& other) = default;
44
47 queue(queue&& other) = default;
48
52 queue& operator=(const queue& other) = default;
53
57 queue& operator=(queue&& other) = default;
58
60 ~queue() = default;
61
66 return mContainer.front();
67 }
68
73 return mContainer.front();
74 }
75
80 return mContainer.back();
81 }
82
87 return mContainer.back();
88 }
89
92 bool empty() const {
93 return mContainer.empty();
94 }
95
98 size_type size() const {
99 return mContainer.size();
100 }
101
104 void push(const value_type& value) {
105 mContainer.push_back(value);
106 }
107
110 void push(value_type&& value) {
111 mContainer.push_back(fl::move(value));
112 }
113
116 void pop() {
117 mContainer.pop_front();
118 }
119
122 void swap(queue& other) {
123 mContainer.swap(other.mContainer);
124 }
125
128 Container& get_container() {
129 return mContainer;
130 }
131
134 const Container& get_container() const {
135 return mContainer;
136 }
137};
138
144template <typename T, typename Container>
146 lhs.swap(rhs);
147}
148
149} // namespace fl
queue()=default
Default constructor - creates an empty queue.
bool empty() const
Check if the queue is empty.
Definition queue.h:92
void push(const value_type &value)
Add an element to the back of the queue.
Definition queue.h:104
queue & operator=(const queue &other)=default
Copy assignment operator.
T value_type
Definition queue.h:20
queue(Container &&container)
Construct queue by moving the given container.
Definition queue.h:39
fl::size size_type
Definition queue.h:21
const Container & get_container() const
Get access to the underlying container (const version)
Definition queue.h:134
queue(queue &&other)=default
Move constructor.
const_reference back() const
Access the last element (back of queue) - const version.
Definition queue.h:86
void swap(queue &other)
Swap the contents with another queue.
Definition queue.h:122
Container container_type
Definition queue.h:24
queue(const Container &container)
Construct queue with a copy of the given container.
Definition queue.h:35
queue(const queue &other)=default
Copy constructor.
Container mContainer
Definition queue.h:27
Container & get_container()
Get access to the underlying container (for advanced use)
Definition queue.h:128
size_type size() const
Get the number of elements in the queue.
Definition queue.h:98
~queue()=default
Destructor.
void pop()
Remove the front element from the queue.
Definition queue.h:116
const T & const_reference
Definition queue.h:23
const_reference front() const
Access the first element (front of queue) - const version.
Definition queue.h:72
void push(value_type &&value)
Add an element to the back of the queue (move version)
Definition queue.h:110
queue & operator=(queue &&other)=default
Move assignment operator.
reference front()
Access the first element (front of queue)
Definition queue.h:65
T & reference
Definition queue.h:22
reference back()
Access the last element (back of queue)
Definition queue.h:79
A first-in, first-out (FIFO) queue container adapter.
Definition queue.h:18
Implements the FastLED namespace macros.
constexpr remove_reference< T >::type && move(T &&t) noexcept
Definition move.h:27
void swap(array< T, N > &lhs, array< T, N > &rhs) noexcept(noexcept(lhs.swap(rhs)))
Definition array.h:156
IMPORTANT!
Definition crgb.h:20