Mixin operator 'if' directly

Neia Neutuladh neia at ikeran.org
Wed Dec 19 15:40:50 UTC 2018


On Wed, 19 Dec 2018 15:12:14 +0000, bauss wrote:
> That's assuming that it's compile-time data though.
> 
> If not then you can't do what you want to do.
> 
> What you can do is wrap it in a function in the mixin template which you
> just call after instantiating it.

Or while instantiating it:

mixin template foo()
{
  int _ignoreme()
  {
    if (readln.strip == "abort") throw new AbortException;
    return 1;
  }
  int _alsoIgnoreMe = _ignoreme();
}
void main()
{
  mixin foo;
}


More information about the Digitalmars-d-learn mailing list