opStar
David B. Held
dheld at codelogicconsulting.com
Mon Nov 12 00:08:38 PST 2007
Michel Fortin wrote:
> [...]
> If you implement the iterator as a struct having a pointer then that's
> perfect with me. If the iterator has a pointer-like syntax, then it
> won't be my prefered syntax, but I can digest. If the iterator has only
> a half-pointer-like syntax -- like needing an explicit parenthesis and
> dereferenciation asterisk (*a).b to access the members of the pointed-to
> element instead of the simpler a.b you can use with a real pointers --
> then that's downright bad in my opinion.
>
> But as I said, I haven't seen what you're planing for iterators, so
> perhaps it's better than what I'm currently imagining.
One thing that should be considered is that people have gotten along
just fine without iterators up until now, so I think it's premature to
say that opStar() is going to bring about the Apocalypse. While it's
true that an operator-> might be nice, consider that a good deal of the
time, Iterators are used in looping constructs, and what does a good D
foreach loop look like?
foreach (object; container)
{
object.useWithoutRegardToPointersOrIterators();
}
So if you could use most iterators without actually seeing them, does it
matter if you have to explicitly say object = *i? You don't have to say
it personally. And hopefully, most algorithms that take iterators as
arguments will also hide this implementation detail. Granted, when you
want to manipulate iterators directly, you will have to treat them like
C-style pointers with manual dereference. But I suspect that when
people start actually using iterators, this won't be so much of an issue.
Dave
More information about the Digitalmars-d
mailing list