CopperSpice API  1.9.1
QQueue< T > Class Template Reference

Template class which provides a queue. More...

Inheritance diagram for QQueue< T >:
QList< T >

Public Methods

 QQueue () = default
 
 ~QQueue () = default
 
dequeue ()
 
void enqueue (const T &value)
 
void enqueue (T &&value)
 
T & head ()
 
const T & head () const
 
void swap (QQueue< T > &other)
 
- Public Methods inherited from QList< T >
 QList () = default
 
 QList (const QList< T > &other) = default
 
template<class Input_Iterator >
 QList (Input_Iterator first, Input_Iterator last)
 
 QList (QList< T > &&other) = default
 
 QList (std::initializer_list< T > args)
 
 ~QList () = default
 
void append (const QList< T > &other)
 
void append (const T &value)
 
void append (QList< T > &&other)
 
void append (T &&value)
 
const T & at (size_type i) const
 
T & back ()
 
const T & back () const
 
iterator begin ()
 
const_iterator begin () const
 
const_iterator cbegin () const
 
const_iterator cend () const
 
void clear ()
 
const_iterator constBegin () const
 
const_iterator constEnd () const
 
const_reference constFirst () const
 
const_reference constLast () const
 
bool contains (const T &value) const
 
size_type count () const
 
size_type count (const T &value) const
 
const_reverse_iterator crbegin () const
 
const_reverse_iterator crend () const
 
bool empty () const
 
iterator end ()
 
const_iterator end () const
 
bool endsWith (const T &value) const
 
iterator erase (const_iterator begin, const_iterator end)
 
iterator erase (const_iterator pos)
 
T & first ()
 
const T & first () const
 
T & front ()
 
const T & front () const
 
size_type indexOf (const T &value, size_type from=0) const
 
iterator insert (iterator before, const T &value)
 
void insert (size_type i, const T &value)
 
bool isEmpty () const
 
T & last ()
 
const T & last () const
 
size_type lastIndexOf (const T &value, size_type from=-1) const
 
size_type length () const
 
QList< T > mid (size_type pos, size_type length=-1) const
 
void move (size_type from, size_type to)
 
bool operator!= (const QList< T > &other) const
 
QList< T > operator+ (const QList< T > &other) const
 
QList< T > & operator+= (const QList< T > &other)
 
QList< T > & operator+= (const T &value)
 
QList< T > & operator<< (const QList< T > &other)
 
QList< T > & operator<< (const T &value)
 
QList< T > & operator= (const QList< T > &other) = default
 
QList< T > & operator= (QList< T > &&other) = default
 
bool operator== (const QList< T > &other) const
 
T & operator[] (size_type i)
 
const T & operator[] (size_type i) const
 
void pop_back ()
 
void pop_front ()
 
void prepend (const T &value)
 
void push_back (const T &value)
 
void push_front (const T &value)
 
reverse_iterator rbegin ()
 
const_reverse_iterator rbegin () const
 
size_type removeAll (const T &value)
 
void removeAt (size_type i)
 
void removeFirst ()
 
void removeLast ()
 
bool removeOne (const T &value)
 
reverse_iterator rend ()
 
const_reverse_iterator rend () const
 
void replace (size_type i, const T &value)
 
void resize (size_type size)
 
size_type size () const
 
bool startsWith (const T &value) const
 
void swap (QList< T > &other)
 
void swap (size_type i, size_type j)
 
takeAt (size_type i)
 
takeFirst ()
 
takeLast ()
 
QSet< T > toSet () const
 
std::list< T > toStdList () const
 
QVector< T > toVector () const
 
value (size_type i) const
 
value (size_type i, const T &defaultValue) const
 

Additional Inherited Members

- Public Typedefs inherited from QList< T >
using allocator_type = typename std::deque< T >::allocator_type
 
using const_iterator = typename std::deque< T >::const_iterator
 
using const_pointer = typename std::deque< T >::const_pointer
 
using const_reference = typename std::deque< T >::const_reference
 
using const_reverse_iterator = typename std::deque< T >::const_reverse_iterator
 
using difference_type = typename std::deque< T >::difference_type
 
using iterator = typename std::deque< T >::iterator
 
using Java_Iterator = QListIterator< T >
 
using Java_MutableIterator = QMutableListIterator< T >
 
using pointer = typename std::deque< T >::pointer
 
using reference = typename std::deque< T >::reference
 
using reverse_iterator = typename std::deque< T >::reverse_iterator
 
using size_type = typename std::deque< T >::difference_type
 
using value_type = typename std::deque< T >::value_type
 
- Static Public Methods inherited from QList< T >
static QList< T > fromSet (const QSet< T > &set)
 
static QList< T > fromStdList (const std::list< T > &other)
 
static QList< T > fromVector (const QVector< T > &vector)
 

Detailed Description

template<class T>
class QQueue< T >

The QQueue class is a template class which provides a stack. This container implements a stack using a QVector. A queue is a first in, first out (FIFO) data structure. Items are added to the tail of the queue using enqueue() and retrieved from the head using dequeue().

For an overview and comparison of all containers, refer to the documentation for Container Classes. Refer to the section on Time Complexity for a discussion about which operations will be relatively faster or slower for a given container with a size of n.

Basic Operations

QQueue inherits from QList so all of the methods in QList are available.

The head() method provides access to the element which was added first, it does not remove it from the queue. To retrieve this element and also remove it, use dequeue(). Use the isEmpty() method to determine if the queue has any elements.

To traverse a QStack the QList iterators can be used.

queue.enqueue(1);
queue.enqueue(2);
queue.enqueue(3);
while (!queue.isEmpty()) {
cout << queue.dequeue() << endl; // output: 1, 2, 3
}

Constraints on type T

The QQueue value type T should be Default Constructible and Copy Constructible to work with all methods of this class. Data types like QObject are not copy constructible and therefore should never be stored in a container. You can however use a pointer to a QObject or any subclass as the type T.

See also
QList, QStack

Constructor & Destructor Documentation

template<class T >
QQueue< T >::QQueue ( )
default

Constructs an empty queue.

template<class T >
QQueue< T >::~QQueue ( )
default

Destroys the queue.

Method Documentation

template<class T >
T QQueue< T >::dequeue ( )
inline

Removes the head item in the queue and returns it. This function assumes that the queue is not empty. Equivalent to calling QList::takeFirst().

See also
head(), enqueue(), isEmpty()
template<class T >
void QQueue< T >::enqueue ( const T &  value)
inline

Adds value to the tail of the queue. Equivalent to calling QList::append().

See also
dequeue(), head()
template<class T >
void QQueue< T >::enqueue ( T &&  value)
inline

Moves value to the tail of the queue. Equivalent to calling QList::append().

See also
dequeue(), head()
template<class T >
T & QQueue< T >::head ( )
inline

Returns a reference to the queue's head item. This method assumes that the queue is not empty. Equivalent to calling QList::first().

See also
dequeue(), enqueue(), isEmpty()
template<class T >
const T & QQueue< T >::head ( ) const
inline

Returns a const reference to the queue's head item. This method assumes that the queue is not empty. Equivalent to calling QList::first().

template<class T >
void QQueue< T >::swap ( QQueue< T > &  other)
inline

Swaps queue other with this queue. This operation is very fast and never fails.