Iterator straw-man
Bill Baxter
dnewsgroup at billbaxter.com
Tue Nov 7 17:21:41 PST 2006
Craig Black wrote:
> I do agree that using classes and interfaces to represent iterators is a bad
> idea for performance reasons. I also agree that I don't think it's
> necessary to support raw pointers.
>
> IMO iterators should be structs such that iteration can be performed as
> follows:
>
> for(auto i = container.begin(); i.isValid(); i.next()) write(i.value);
>
> If I am not mistaken, this can already be done in D. With foreach support
> this would simplify to.
>
> foreach(i; container) write(i);
I haven't read Seans big long proposal yet, but I think the method that
returns an iterator should not be called 'begin'. I should be called
'forward' or 'iterator' or 'iter' or 'forward_iterator' or something
like that.
Then i would hope that all of the following would be possible:
foreach(i; container.iter) write(i);
foreach(i; container.reverse_iter) write(i);
foreach(i; container.my_skip_every_prime_number_iter) write(i);
foreach(i; container) can look for the .iter (or opIterator, or whatever
standard name is decided upon).
foreach_reverse(i; container) [shudder] can look for the .riter (or
opIteratorReverse, or whatever).
--bb
More information about the Digitalmars-d
mailing list