Container hierarchy vs. container types

Michel Fortin michel.fortin at
Fri Mar 5 09:04:08 PST 2010

On 2010-03-05 11:32:27 -0500, Jonathan M Davis <jmdavisProg at> 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?

Michel Fortin
michel.fortin at

More information about the Digitalmars-d mailing list