Are iterators and ranges going to co-exist?
Jonathan M Davis
jmdavisprog at gmail.com
Wed Jul 21 15:03:41 PDT 2010
On Wednesday, July 21, 2010 14:39:38 Peter Alexander wrote:
> I also find it unintuitive to write insertBefore(Range). Why is it
> asking me for a range when it's going to ignore everything but the first
> element? Why can't I just pass in the single position I want to insert
> before? The same applies for insertAfter.
Well, considering that any function that you'd be dealing with at this point
would give you a range, it's quite natural that what you'd have to pass to
insertBefore() would be a range. And really, that's all you need anyway. The
first element of the range is what you'd have had an iterator for anyway, so
you're really doing the same thing. It's just that you have a whole range
instead of the single iterator.
Granted, it does seem a little funny to have whole ranges for this, but it works
just fine, and trying to mix iterators into phobos will just make it more
complicated, and cause concerns for when iterators should be used vs when ranges
should be used, as well as how to convert from one to the other.
It may be that we need to find a way to extend the functionality of ranges such
that some of the more awkward cases are less awkward, but ranges work, and they
generally work very well. It just requires thinking about things a bit
differently.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list