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]); } ```
Timothee Cour via Digitalmars-d-learn Tue, 13 Dec 2016 15:01:51 -0800
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]); } ```