templated overload of opAssign

kdevel kdevel at vogtner.de
Sat Apr 3 13:46:17 UTC 2021


Why does this code

```d
import std.stdio,std.typecons;

struct EC {
    Exception [] ex;
    auto opAssign (X: void) (lazy X f)
    {
       writeln (__PRETTY_FUNCTION__);
       try return f (); catch (Exception e) ex ~= e;
    }
}

class E : Exception { this (string s) { super (s); } }
void bar (int i) { if (i == 1) throw new E ("E"); }

void main ()
{
    EC ec;

    ec.opAssign (bar (1)); // okay
//   ec = bar (1); // Error: expression bar(1) is void and has no 
value

    ec.writeln;
}
```

compile with the abovementioned error?


More information about the Digitalmars-d-learn mailing list