www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 21904] New: static range primitives should be usable directly

https://issues.dlang.org/show_bug.cgi?id=21904

          Issue ID: 21904
           Summary: static range primitives should be usable directly
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: b2.temp gmx.com

To iterate over a type that define the input range primitive, we must define
an alias this:

---
struct Conv
{
    static StaticIterable b;
    alias b this;
}

struct StaticIterable
{
    static Conv b; alias b this;    // required
                                    // enhancement: could work without ?

    static void popFront()  {               }
    static bool empty()     { return true;  }
    static int  front()     { return 0;     }
}

void main()
{
    foreach (int i; StaticIterable){}

    //for (; !StaticIterable.empty(); StaticIterable.popFront())
    //    int i = StaticIterable.front();
}

--
May 07