www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 12583] New: Allow user defined "retro" range


          Issue ID: 12583
           Summary: Allow user defined "retro" range
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: Phobos
          Assignee: nobody puremagic.com
          Reporter: monarchdodra gmail.com

I have a use case, where I have a range [*] "Range myRange" whose behavior is
biased in favor of forwards iteration. Backwards iteration is also possible,
but more costly.

That said, I have a RetroRange, that iterates the same thing as my Range, but
in reverse order, and more efficiently than what I'd get with "retro(myRange)".

I've implemented the "retro()" member functions on both these ranges, so
flipping iteration scheme is as simple as calling ".retro()".

I think the "retro()" member function should be a range trait that is
recognized by std.range.retro. This way, one can write either of
"myRange.retro()" or "retro(myRange)" and have the same, customized high
performance result.


[*] These kinds of range are usually those that iterate over containers, where
it is most efficient to store _first and _pastTheEnd elements. In particular,
linked list or binary trees.

Other ranges could also benefit from this approach. For example, zip: finding
the back of zip is no trivial operation. However, a type specifically designed
to zip backwards could be *much* more efficient.

Apr 15 2014