How to define an interator to provide array like behaviour in a class?

Jonathan M Davis jmdavisProg at gmx.com
Wed Oct 17 08:45:16 PDT 2012


On Wednesday, October 17, 2012 08:58:33 Jacob Carlborg wrote:
> On 2012-10-17 08:17, Jonathan M Davis wrote:
> > For starters, iterating over the container would empty it.
> 
> Right, but that is really weird, in my opinion.

Well, what would you expect? Ranges are consumed when you iterate over them. 
So, if an container is a range, it will be consumed when you iterate over it. 
That's the way that it _has_ to work given how ranges work, and that's why you 
overload opSlice to return a range which is iterated over rather than making 
the container itself a range.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list