Summary: Add template mixin for Range Primitives using random
           Product: D
           Version: D2
          Platform: Other
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: Phobos

--- Comment #0 from Jesse Phillips <> 2010-12-14 
09:27:14 PST ---
This came form a post by Lars on how to remove the boilerplate if you already
have a random access interface:

To avoid the boilerplate, you could write a mixin that defines the
iteration primitives for you.

  mixin template IterationFuncs()
      int index;
      bool empty() { return index == length; }
      auto front() { return opIndex(index); }
      void popFront() { ++index; }
      // ... etc.

Then you'd just have to define opIndex() and length(), and the mixin does
the rest for you.

  struct MyRange(T)
      T opIndex(int i) { ... }
      @property int length() { ... }
      mixin IterationFuncs!();

(I haven't tested the code above, so it probably has bugs, but you get
the point.)


Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to