[Issue 21904] New: static range primitives should be usable directly

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri May 7 17:23:44 UTC 2021


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 at puremagic.com
          Reporter: b2.temp at 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();
}

--


More information about the Digitalmars-d-bugs mailing list