QQueue容器存在的目的是什么?

What is the purpose of the existence of the QQueue container?

我从那时起就开始使用 Qt,并且一直在 QQueue 对象上使用 QQueue class as a replacement for std::queue. Though today I figured that I was able to use the pop_front, pop_back, push_front and push_back functions from the QList class。想知道为什么你可以在队列上使用这些函数(尤其是 pop_backpush_front),我查了一下Qt 文档,并认为 QQueue 继承了 QList。

对我来说,队列的主要兴趣是充当队列:在后面入队,在前面出队。但是当我继续阅读文档时,我发现 QList 的 enqueue and dequeue functions were just equivalents to the append and takeFirst functions of the QList class. Even the head function is identical to the first 函数。最重要的是,使用 pop_backpush_front 等函数的可能性完全打破了 a 的初始逻辑为我排队,而文档本身将 QQueue class 作为队列容器呈现:

The QQueue class is a generic container that provides a queue.

QQueue is one of Qt's generic container classes. It implements a queue data structure for items of a same type.

A queue is a first in, first out (FIFO) structure. Items are added to the tail of the queue using enqueue() and retrieved from the head using dequeue(). The head() function provides access to the head item without removing it.

关于 QQueue class 存在的目的,我是否遗漏了什么?我的意思是,为什么要创建这个队列容器,以便它可以做比队列应该做的更多的事情?由于 QQueue class 似乎能够以与 QList 完全相同的方式工作,是否有任何理由在 QList 上使用 QQueue?

QQueue 本身继承自 QList 并简单地添加了一些方法,这些方法已经以不同的名称出现在 QList 中。除了语法糖之外,没有其他用处。

containers description 中所述:

QStack and QQueue are convenience classes that provide LIFO and FIFO semantics.

唯一的区别是您提到的其他方法

重点是语义上更合适且直观的方法命名

否则:

  • QQueue 与其基数 class QList.
  • 相同
  • QStack 与其基数 class QVector.
  • 相同

自己看看,看看 源代码 – 这些 classes:

中没有任何额外内容