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