38#ifndef __BASE_CIRCULAR_QUEUE_HH__
39#define __BASE_CIRCULAR_QUEUE_HH__
115 static_assert(std::is_same_v<reference, T&>,
116 "reference type is not assignable as required");
341 return (ssize_t)
_idx - (ssize_t)that.
_idx;
350 template<
typename Idx>
351 typename std::enable_if_t<std::is_integral_v<Idx>,
reference>
354 return *(*
this +
index);
393 template <
typename Idx>
394 typename std::enable_if_t<std::is_integral_v<Idx>,
reference>
401 template <
typename Idx>
479 assert(num_elem <=
size());
535 if (
len > remaining) {
536 size_t overflow =
len - remaining;
bool isValidIdx(size_t idx) const
Test if the index is in the range of valid elements.
std::enable_if_t< std::is_integral_v< Idx >, const_reference > operator[](const Idx &index) const
typename std::vector< T >::reference reference
iterator getIterator(size_t idx)
Return an iterator to an index in the queue.
typename std::vector< T >::const_reference const_reference
CircularQueue(size_t size=0)
std::enable_if_t< std::is_integral_v< Idx >, reference > operator[](const Idx &index)
Index operator.
T value_type
Iterator Traits.
const value_type * const_pointer
void push_back(typename std::vector< T >::value_type val)
Pushes an element at the end of the queue.
bool operator<(const iterator &that) const
Comparisons.
pointer operator->()
Dereference operator.
difference_type operator-(const iterator &that)
Difference operator.
void flush()
Remove all the elements in the queue.
const_reference operator*() const
iterator & operator--()
ForwardIterator The multipass guarantee is provided by the reliance on _idx.
bool operator>=(const iterator &that) const
iterator operator-(const difference_type &t)
Substraction operator.
std::ptrdiff_t difference_type
friend iterator operator+(const difference_type &t, iterator &it)
void pop_front(size_t num_elem=1)
Circularly increase the head pointer.
iterator & operator+=(const difference_type &t)
RandomAccessIterator requirements.
bool operator==(const iterator &that) const
InputIterator.
bool dereferenceable() const
Test dereferenceability.
bool empty() const
Is the queue empty?
iterator operator++(int)
Post-increment operator.
friend iterator operator-(const difference_type &t, iterator &it)
const value_type & const_reference
void pop_back()
Circularly decrease the tail pointer.
iterator operator--(int)
Post-decrement operator.
bool operator!=(const iterator &that)
Inequality operator.
std::random_access_iterator_tag iterator_category
void advance_tail()
Increases the tail by one.
iterator & operator=(const iterator &it)
iterator(const iterator &it)
Trait reference type iterator satisfies OutputIterator, therefore reference must be T&.
iterator operator+(const difference_type &t)
Addition operator.
bool operator>(const iterator &that) const
std::enable_if_t< std::is_integral_v< Idx >, reference > operator[](const Idx &index)
bool full() const
Is the queue full? A queue is full if the head is the 0^{th} element and the tail is the (size-1)^{th...
iterator begin()
Iterators.
void advance_tail(size_t len)
Increases the tail by a specified number of steps.
bool operator<=(const iterator &that) const
iterator & operator-=(const difference_type &t)
const_pointer operator->() const
reference operator*()
Dereference operator.
iterator & operator++()
Pre-increment operator.
iterator(CircularQueue *cq, size_t idx)
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Iterator to the circular queue.
size_t idx() const
OutputIterator has no extra requirements.