Container adapters do not support iterators

One STL C ++ article says that -

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

But he did not explain why container adapters do not support iterators? Can someone explain the same to me?

+6
source share
2 answers

What point in the stack or queue does the iterator have? The stack is something that you can only click and paste ... An iterator will destroy the whole purpose of these adapters.

+6
source

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

That is, the Container Adapters provided in the STL do not support iteration, since they limit the interface to a particular model:

  • The stack can only be processed from one end.
  • In the queue, you can only click on one end and remove from the other

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

+1
source

Source: https://habr.com/ru/post/891944/


All Articles