ladybird/AK/CircularDeque.h
Andreas Kling 0cea80218d AK: Make it possible to store complex types in a CircularQueue
Previously we would not run destructors for items in a CircularQueue,
which would lead to memory leaks.

This patch fixes that, and also adds a basic unit test for the class.
2019-10-23 12:27:43 +02:00

26 lines
490 B
C++

#pragma once
#include <AK/Assertions.h>
#include <AK/CircularQueue.h>
#include <AK/Types.h>
namespace AK {
template<typename T, int Capacity>
class CircularDeque : public CircularQueue<T, Capacity> {
public:
T dequeue_end()
{
ASSERT(!this->is_empty());
auto& slot = this->elements()[(this->m_head + this->m_size - 1) % Capacity];
T value = move(slot);
slot.~T();
this->m_size--;
return value;
}
};
}
using AK::CircularDeque;