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:
Lenny Maiorani 2021-01-15 15:51:50 -07:00 committed by Andreas Kling
parent 73d6c73b48
commit b754121da7

View file

@ -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());