__traits(compiles) + mixin

simendsjo simendsjo at gmail.com
Tue Mar 5 00:14:57 PST 2013


On Tuesday, 5 March 2013 at 08:09:37 UTC, cal wrote:
> On Tuesday, 5 March 2013 at 08:04:12 UTC, Andrej Mitrovic wrote:
>> You can't test declarations inside of __traits(compiles), only 
>> expressions. It's in the docs: 
>> http://dlang.org/traits.html#compiles
>
> So why does this work:
>
> import std.conv;
>
> void main()
> {
>     enum s = "`1`.to!int;";
>     enum c = __traits(compiles, mixin("{auto x = "~s~";}")); // 
> true
> }

Hmm.. And this also works:
enum c = __traits(compiles, mixin("{auto a = new 1;}"));

Something to do with CTFE combined with mixins?


More information about the Digitalmars-d-learn mailing list