-
Notifications
You must be signed in to change notification settings - Fork 70
Expand file tree
/
Copy pathqueue.h
More file actions
235 lines (203 loc) · 5.09 KB
/
queue.h
File metadata and controls
235 lines (203 loc) · 5.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#pragma once
namespace fast_io
{
namespace containers
{
template <typename Container>
class queue
{
public:
using container_type = Container;
using value_type = typename container_type::value_type;
using size_type = typename container_type::size_type;
using reference = typename container_type::reference;
using const_reference = typename container_type::const_reference;
container_type container;
inline constexpr queue() noexcept = default;
template <::std::ranges::range R>
inline explicit constexpr queue(::fast_io::freestanding::from_range_t, R &&rg)
: container(::fast_io::freestanding::from_range, ::std::forward<R>(rg))
{}
inline constexpr container_type const &get_container() const noexcept
{
return container;
}
inline constexpr container_type &get_container() noexcept
{
return container;
}
inline constexpr reference front() noexcept
{
return container.front();
}
inline constexpr const_reference front() const noexcept
{
return container.front();
}
inline constexpr reference front_unchecked() noexcept
{
return container.front_unchecked();
}
inline constexpr const_reference front_unchecked() const noexcept
{
return container.front_unchecked();
}
inline constexpr reference back() noexcept
{
return container.back();
}
inline constexpr const_reference back() const noexcept
{
return container.back();
}
inline constexpr reference back_unchecked() noexcept
{
return container.back_unchecked();
}
inline constexpr const_reference back_unchecked() const noexcept
{
return container.back_unchecked();
}
#if __has_cpp_attribute(__gnu__::__pure__)
[[__gnu__::__pure__]]
#endif
[[nodiscard]]
inline constexpr bool empty() const noexcept
{
if constexpr (requires() {
{ container.is_empty() } -> ::std::convertible_to<bool>;
})
{
return container.is_empty();
}
else
{
return container.empty();
}
}
#if __has_cpp_attribute(__gnu__::__pure__)
[[__gnu__::__pure__]]
#endif
[[nodiscard]]
inline constexpr bool is_empty() const noexcept
{
return container.is_empty();
}
#if __has_cpp_attribute(__gnu__::__pure__)
[[__gnu__::__pure__]]
#endif
[[nodiscard]]
inline constexpr size_type size() const noexcept
requires(requires() {
container.size();
})
{
return container.size();
}
inline constexpr void push(value_type const &value)
{
container.push_back(value);
}
inline constexpr void push(value_type &&value)
{
container.push_back(::std::move(value));
}
inline constexpr void reserve(size_type newcap) noexcept
{
container.reserve(newcap);
}
inline constexpr void push_unchecked(value_type const &value)
{
container.push_back_unchecked(value);
}
inline constexpr void push_unchecked(value_type &&value)
{
container.push_back_unchecked(::std::move(value));
}
template <typename... Args>
requires ::std::constructible_from<value_type, Args...>
inline constexpr reference emplace(Args &&...args) noexcept
{
return container.emplace_back(::std::forward<Args>(args)...);
}
template <typename... Args>
requires ::std::constructible_from<value_type, Args...>
inline constexpr reference emplace_unchecked(Args &&...args) noexcept
{
return container.emplace_back_unchecked(::std::forward<Args>(args)...);
}
template <::std::ranges::range R>
inline constexpr void push_range(R &&rg)
{
container.append_range(::std::forward<R>(rg));
}
inline constexpr void pop() noexcept
{
container.pop_front();
}
inline constexpr void pop_unchecked() noexcept
{
container.pop_front_unchecked();
}
inline constexpr value_type pop_element() noexcept
requires(::std::move_constructible<value_type>)
{
value_type front(::std::move(container.front()));
if constexpr (requires() {
{ container.pop_front_unchecked() };
})
{
container.pop_front_unchecked();
}
else
{
container.pop_front();
}
return front;
}
inline constexpr value_type pop_element_unchecked() noexcept
requires(::std::move_constructible<value_type>)
{
value_type front(::std::move(container.front_unchecked()));
if constexpr (requires() {
{ container.pop_front_unchecked() };
})
{
container.pop_front_unchecked();
}
else
{
container.pop_front();
}
return front;
}
inline constexpr void clear() noexcept
{
container.clear();
}
inline constexpr void clear_destroy() noexcept
{
container.clear_destroy();
}
inline constexpr void swap(::fast_io::containers::queue<Container> &b) noexcept
{
container.swap(b.container);
}
};
template <typename Container>
inline constexpr bool operator==(::fast_io::containers::queue<Container> const &a, ::fast_io::containers::queue<Container> const &b) noexcept
{
return a.container == b.container;
}
template <typename Container>
inline constexpr auto operator<=>(::fast_io::containers::queue<Container> const &a, ::fast_io::containers::queue<Container> const &b) noexcept
{
return a.container <=> b.container;
}
template <typename Container>
inline constexpr void swap(::fast_io::containers::queue<Container> &a, ::fast_io::containers::queue<Container> &b) noexcept
{
a.swap(b);
}
} // namespace containers
} // namespace fast_io