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

2016-12-15 Thread Timon Gehr via Digitalmars-d-learn
On 15.12.2016 01:38, Basile B. wrote: On Wednesday, 14 December 2016 at 22:06:35 UTC, Ali Çehreli wrote: On 12/14/2016 09:25 AM, Basile B. wrote: > On Tuesday, 13 December 2016 at 23:37:59 UTC, Timon Gehr wrote: >> I usually do >> >> enum code = q{expr}; >> static

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

2016-12-14 Thread Basile B. via Digitalmars-d-learn
On Wednesday, 14 December 2016 at 22:06:35 UTC, Ali Çehreli wrote: On 12/14/2016 09:25 AM, Basile B. wrote: > On Tuesday, 13 December 2016 at 23:37:59 UTC, Timon Gehr wrote: >> I usually do >> >> enum code = q{expr}; >> static if(__traits(compiles,mixin(code))) >> fun(mixin(code)); > >

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

2016-12-14 Thread Ali Çehreli via Digitalmars-d-learn
On 12/14/2016 09:25 AM, Basile B. wrote: > On Tuesday, 13 December 2016 at 23:37:59 UTC, Timon Gehr wrote: >> I usually do >> >> enum code = q{expr}; >> static if(__traits(compiles,mixin(code))) >> fun(mixin(code)); > > Strangely if i put this in a templated enum that doesn't work. > If

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

2016-12-14 Thread Basile B. via Digitalmars-d-learn
On Tuesday, 13 December 2016 at 23:37:59 UTC, Timon Gehr wrote: On 14.12.2016 00:00, Timothee Cour via Digitalmars-d-learn wrote: what's the best (and DRY) way to achieve: ``` static if(__traits(compiles, expr)) fun(expr); ``` ie, without repeating the expression inside expr? eg: ```

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

2016-12-13 Thread Timon Gehr via Digitalmars-d-learn
On 14.12.2016 00:00, Timothee Cour via Digitalmars-d-learn wrote: 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("

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

2016-12-13 Thread Timothee Cour via Digitalmars-d-learn
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]); } ```