On Fri, Jun 7, 2013 at 7:05 AM, Daniel Micay <[email protected]> wrote:
> On Fri, Jun 7, 2013 at 12:58 AM, Sebastian Sylvan > <[email protected]> wrote: > > The linked article contrasts them with the GoF-style iterators as well. > > > > The Rust Iterator trait is similar to the "one pass ranges" (and possibly > > forward ranges), but not double-ended ranges or random-access ranges. > It's > > the *family* of range-based iterators that makes it flexible (e.g. > allowing > > you to write an efficient in-place reverse without knowing the underlying > > data structure, using a double-ended range). > > > > See fig. 3: > > > http://www.informit.com/content/images/art_alexandrescu3_iterators/elementLinks/alexandrescu3_fig03.jpg > > The extent to which you can have mutable iterators in Rust is pretty > small, because of the memory safety requirement. Iterators can't open > up a hole allowing multiple mutable references to the same object to > be obtained, so I don't think mutable bidirectional or random access > iterators are possible. > > Forward iterators can't ever give you an alias because they're a > single pass over the container. It's an easy guarantee to provide. > Is it ? In this case it would mean that you can only have one Forward Iterator in scope (for a given container) at once too (ie, the forward iterator borrows the container); otherwise you could have two distinct iterators pointing to the same underlying element. I certainly appreciate the ongoing debate anyway, it's great to see things being exposed to light and openly discussed. I would like to contribute with one point: partitioning. Sometimes, you would like to partition a container, or point to one of its elements. For example, in C++, you have an overload of insert which takes an iterator allowing you to point to the routine where the element you ask to insert is likely to go and thus shaving off a couple comparisons (if you are right). This requires pointing to a single element, to be contrasted with a range. Another example would be partitioning, a partition of a slice can be represented with two points: the two end-points of the slice and the point of partition. Both of those examples can be represented by ranges (or in C++ iterator) though they do not themselves imply any iteration. My point, thus, is that there might be a need for "fingers inside a container" that go beyond basic iteration. -- Matthieu > _______________________________________________ > Rust-dev mailing list > [email protected] > https://mail.mozilla.org/listinfo/rust-dev >
_______________________________________________ Rust-dev mailing list [email protected] https://mail.mozilla.org/listinfo/rust-dev
