diff --git a/BAN/include/BAN/CircularQueue.h b/BAN/include/BAN/CircularQueue.h index 28554c5c..9400d81d 100644 --- a/BAN/include/BAN/CircularQueue.h +++ b/BAN/include/BAN/CircularQueue.h @@ -34,6 +34,11 @@ namespace BAN const T& back() const; T& back(); + const T& operator[](size_t index) const; + T& operator[](size_t index); + + void clear(); + size_type size() const { return m_size; } bool empty() const { return size() == 0; } bool full() const { return size() == capacity(); } @@ -53,8 +58,7 @@ namespace BAN template CircularQueue::~CircularQueue() { - for (size_type i = 0; i < m_size; i++) - element_at((m_first + i) % capacity())->~T(); + clear(); } template @@ -115,6 +119,28 @@ namespace BAN return *element_at((m_first + m_size - 1) % capacity()); } + template + const T& CircularQueue::operator[](size_t index) const + { + ASSERT(index < m_size); + return *element_at((m_first + index) % capacity()); + } + + template + T& CircularQueue::operator[](size_t index) + { + ASSERT(index < m_size); + return *element_at((m_first + index) % capacity()); + } + + template + void CircularQueue::clear() + { + for (size_type i = 0; i < m_size; i++) + element_at((m_first + i) % capacity())->~T(); + m_size = 0; + } + template const T* CircularQueue::element_at(size_type index) const {