Michel Fortin wrote:
On 2010-03-05 11:32:27 -0500, Jonathan M Davis <jmdavisp...@gmail.com> said:

Why couldn't a container have the same interface as a range, only with
the added ability to push elements into it?

Probably because it would become way too easy to accidentally use the
container as a range, which in many cases would end up emptying it when
passing it to one of the std algorithms.

Yes, I understand that.

My point is that the problem already exists with ranges: by exposing a stream as a range, you'll empty the stream when iterating over it. If that's acceptable for streams, why is it not for containers?

And perhaps you actually want to empty the container as you iterate over it. If you use your container as a queue, that's what you'll expect. In fact, a stream is just like a queue, and you want algorithms to work on streams don't you?

A range is a view on a container. As such, popping off a range does not affect the topology of the underlying container. Consider, for contrast, a balanced binary tree. Removing an element triggers a rebalance of the tree, but popping an element off an iterator in that tree does not affect the tree itself.

Fair enough?


Andrei

Reply via email to