DRY version of `static if(__traits(compiles, expr)) fun(expr)`

Timothee Cour via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Dec 13 15:00:10 PST 2016


what's the best (and DRY) way to achieve:

```
static if(__traits(compiles, expr))
  fun(expr);
```

ie, without repeating the expression inside expr?

eg:

```
static if(__traits(compiles, foo.bar[2])){
  counter++;
  writeln(" expr = ", foo.bar[2]);
}

```
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20161213/9c959425/attachment.html>


More information about the Digitalmars-d-learn mailing list