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
// Qt-Security score:significant reason:default
4
5
/*!
6
\class QQueue
7
\inmodule QtCore
8
\brief The QQueue class is a generic container that provides a queue.
9
10
\ingroup tools
11
\ingroup shared
12
\ingroup containers
13
14
\reentrant
15
16
QQueue<T> is one of Qt's generic \l{container classes}, where
17
\a T specifies the element type. It implements a queue data structure
18
for items of a same type.
19
20
A queue is a first in, first out (FIFO) structure. Items are
21
added to the tail of the queue using enqueue() and retrieved from
22
the head using dequeue(). The head() function provides access to
23
the head item without removing it.
24
25
Example:
26
\snippet code/src_corelib_tools_qqueue.cpp 0
27
28
The example will output 1, 2, 3 in that order.
29
30
QQueue inherits from QList. All of QList's functionality also
31
applies to QQueue. For example, you can use isEmpty() to test
32
whether the queue is empty, and you can traverse a QQueue using
33
QList's iterator classes (for example, QListIterator). But in
34
addition, QQueue provides three convenience functions that make
35
it easy to implement FIFO semantics: enqueue(), dequeue(), and
36
head().
37
38
QQueue's value type must be an \l{assignable data type}. This
39
covers most data types that are commonly used, but the compiler
40
won't let you, for example, store a QWidget as a value. Use
41
QWidget* instead.
42
43
\sa QList, QStack
44
*/
45
46
/*!
47
\fn template <class T> void QQueue<T>::swap(QQueue<T> &other)
48
\since 4.8
49
\memberswap{queue}
50
*/
51
52
/*!
53
\fn template <class T> void QQueue<T>::enqueue(const T& t)
54
\fn template <class T> void QQueue<T>::enqueue(T&& t)
55
56
Adds value \a t to the tail of the queue.
57
58
This is the same as QList::append().
59
60
\sa dequeue(), head()
61
*/
62
63
/*!
64
\fn template <class T> T &QQueue<T>::head()
65
66
Returns a reference to the queue's head item. This function
67
assumes that the queue isn't empty.
68
69
This is the same as QList::first().
70
71
\sa dequeue(), enqueue(), isEmpty()
72
*/
73
74
/*!
75
\fn template <class T> const T &QQueue<T>::head() const
76
77
\overload
78
*/
79
80
/*!
81
\fn template <class T> T QQueue<T>::dequeue()
82
83
Removes the head item in the queue and returns it. This function
84
assumes that the queue isn't empty.
85
86
This is the same as QList::takeFirst().
87
88
\sa head(), enqueue(), isEmpty()
89
*/
qtbase
src
corelib
tools
qqueue.cpp
Generated on
for Qt by
1.16.1