www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 5351] New: Add template mixin for Range Primitives using random access

http://d.puremagic.com/issues/show_bug.cgi?id=5351

           Summary: Add template mixin for Range Primitives using random
                    access
           Product: D
           Version: D2
          Platform: Other
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: Jesse.K.Phillips+D gmail.com
                CC: Jesse.K.Phillips+D gmail.com



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.)

-Lars

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 14 2010