mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-12 09:20:36 +00:00
Queue: Correctly pass args to enqueue
Problem: - Using regular functions rather than function templates results in the arguments not being deduced. This then requires the same function to be written multiple times and for `move` to be used rather than `forward`. Solution: - Collapse multiple function overloads to a single function template with a deduced argument. This allows the argument to be a forwarding reference and bind to either an l-value or r-value and forward the value.
This commit is contained in:
parent
73d6c73b48
commit
b754121da7
Notes:
sideshowbarker
2024-07-18 22:42:32 +09:00
Author: https://github.com/ldm5180 Commit: https://github.com/SerenityOS/serenity/commit/b754121da73 Pull-request: https://github.com/SerenityOS/serenity/pull/5193
1 changed files with 3 additions and 7 deletions
10
AK/Queue.h
10
AK/Queue.h
|
@ -41,19 +41,15 @@ public:
|
|||
size_t size() const { return m_size; }
|
||||
bool is_empty() const { return m_size == 0; }
|
||||
|
||||
void enqueue(T&& value)
|
||||
template<typename U = T>
|
||||
void enqueue(U&& value)
|
||||
{
|
||||
if (m_segments.is_empty() || m_segments.last()->size() >= segment_size)
|
||||
m_segments.append(make<Vector<T, segment_size>>());
|
||||
m_segments.last()->append(move(value));
|
||||
m_segments.last()->append(forward<U>(value));
|
||||
++m_size;
|
||||
}
|
||||
|
||||
void enqueue(const T& value)
|
||||
{
|
||||
enqueue(T(value));
|
||||
}
|
||||
|
||||
T dequeue()
|
||||
{
|
||||
ASSERT(!is_empty());
|
||||
|
|
Loading…
Reference in a new issue