Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qqueue.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4/*!
5 \class QQueue
6 \inmodule QtCore
7 \brief The QQueue class is a generic container that provides a queue.
8
9 \ingroup tools
10 \ingroup shared
11
12 \reentrant
13
14 QQueue<T> is one of Qt's generic \l{container classes}. It
15 implements a queue data structure for items of a same type.
16
17 A queue is a first in, first out (FIFO) structure. Items are
18 added to the tail of the queue using enqueue() and retrieved from
19 the head using dequeue(). The head() function provides access to
20 the head item without removing it.
21
22 Example:
23 \snippet code/src_corelib_tools_qqueue.cpp 0
24
25 The example will output 1, 2, 3 in that order.
26
27 QQueue inherits from QList. All of QList's functionality also
28 applies to QQueue. For example, you can use isEmpty() to test
29 whether the queue is empty, and you can traverse a QQueue using
30 QList's iterator classes (for example, QListIterator). But in
31 addition, QQueue provides three convenience functions that make
32 it easy to implement FIFO semantics: enqueue(), dequeue(), and
33 head().
34
35 QQueue's value type must be an \l{assignable data type}. This
36 covers most data types that are commonly used, but the compiler
37 won't let you, for example, store a QWidget as a value. Use
38 QWidget* instead.
39
40 \sa QList, QStack
41*/
42
43/*!
44 \fn template <class T> void QQueue<T>::swap(QQueue<T> &other)
45 \since 4.8
46 \memberswap{queue}
47*/
48
49/*!
50 \fn template <class T> void QQueue<T>::enqueue(const T& t)
51
52 Adds value \a t to the tail of the queue.
53
54 This is the same as QList::append().
55
56 \sa dequeue(), head()
57*/
58
59/*!
60 \fn template <class T> T &QQueue<T>::head()
61
62 Returns a reference to the queue's head item. This function
63 assumes that the queue isn't empty.
64
65 This is the same as QList::first().
66
67 \sa dequeue(), enqueue(), isEmpty()
68*/
69
70/*!
71 \fn template <class T> const T &QQueue<T>::head() const
72
73 \overload
74*/
75
76/*!
77 \fn template <class T> T QQueue<T>::dequeue()
78
79 Removes the head item in the queue and returns it. This function
80 assumes that the queue isn't empty.
81
82 This is the same as QList::takeFirst().
83
84 \sa head(), enqueue(), isEmpty()
85*/