On Thursday, 19 June 2014 at 22:22:33 UTC, w0rp wrote:

I haven't yet figured out a good way to make opApply implementations get all of the nice qualifiers without writing a bunch of overloads.

I don't know how practical this is, but since attributes are
inferred for templated methods ...

struct S
{
     int opApply(Dg : int delegate(ref int))(Dg dg)
     {
         int e;
         return dg(e);
     }
}
void f1() pure nothrow @nogc @safe
{
     S s;
     foreach(int x; s) {}
}
void f2()
{
     S s;
     import std.stdio;
     foreach(int x; s) writeln(x);
}
void main()
{
     f1();
     f2();
}

Reply via email to