From a2501c398164b26f932a32342865503d5dfe9361 Mon Sep 17 00:00:00 2001 From: Lenny Maiorani Date: Fri, 15 Jan 2021 15:55:36 -0700 Subject: [PATCH] CircularDeque: 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. --- AK/CircularDeque.h | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/AK/CircularDeque.h b/AK/CircularDeque.h index 06cd66a528..06b91e2012 100644 --- a/AK/CircularDeque.h +++ b/AK/CircularDeque.h @@ -35,7 +35,8 @@ namespace AK { template class CircularDeque : public CircularQueue { public: - void enqueue_begin(T&& value) + template + void enqueue_begin(U&& value) { const auto new_head = (this->m_head - 1 + Capacity) % Capacity; auto& slot = this->elements()[new_head]; @@ -44,15 +45,10 @@ public: else ++this->m_size; - new (&slot) T(move(value)); + new (&slot) T(forward(value)); this->m_head = new_head; } - void enqueue_begin(const T& value) - { - enqueue_begin(T(value)); - } - T dequeue_end() { ASSERT(!this->is_empty());