Container Adapters do not support iterators

感情迁移 提交于 2020-01-13 09:41:54

问题


In one of the C++ articles on STL, is being said that -

Since container adapters do not support iterators, hence they cannot be used with the STL algorithms.

But it did not explain as to why Container Adapters do not support iterators? Can anybody explain me the same?


回答1:


What's the point of a stack or a queue having an iterator? A stack is by definition something that you can only push and pop into... An iterator would destroy the whole purpose of these adapters




回答2:


I would note that this is only an observation, not a rule.

That is, the Container Adapters provided in the STL do not support iteration, because they restrict the interface to conform to a specific model:

  • A stack may only be manipulated at one end
  • In a queue you may only push at one end and retrieve from the other

However, this is not a rule, and you may decide to create adapters that will support iteration.



来源:https://stackoverflow.com/questions/6569412/container-adapters-do-not-support-iterators

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!