[英]Why std::queue doesn't implement insert() while std::deque does?
Insert allows insertion into an arbitrary position into the structure. 插入允许插入到结构的任意位置。
std::queue
is an abstract interface for a FIFO structure. std::queue
是FIFO结构的抽象接口。 You can only add things to the end. 您只能在最后添加内容。 The underlying structure doesn't necessarily have an efficient way to insert into arbitrary position (consider
std::vector
for example). 底层结构不一定具有插入任意位置的有效方法(例如,考虑
std::vector
)。 Therefore std::queue
has no general insert member function. 因此
std::queue
没有通用的插入成员函数。
Since the general insertion function requires the iterator position argument, the multiple-insert is provided as a convenience, so that you don't have to keep track of the next iterator position. 由于常规插入函数需要迭代器位置参数,因此为方便起见提供了多次插入,因此您不必跟踪下一个迭代器位置。 The push back doesn't have need for this because no iterator tracking is needed and a trivial loop is sufficient.
不需要回推,因为不需要迭代器跟踪并且微不足道的循环就足够了。
std::queue
is an adapter that is intended to be limited to push/pop interfaces. std::queue
是一个适配器, 旨在限制于推/弹出接口。 It will not expose insert
even if std::vector
is an underlying implementation. 即使
std::vector
是基础实现,它也不会公开insert
。
There are no particular performance reasons, merely a design approach: if you feel that your container is a queue, you just do not expose interfaces you don't need. 没有特殊的性能原因,仅是一种设计方法:如果您觉得容器是一个队列,那么就不必公开不需要的接口。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.