Re: __traits(compiles , mixin ... )

2017-10-25 Thread SrMordred via Digitalmars-d-learn
s that are syntactically correct. The arguments cannot be statements or declarations. " When there's a closing ;, it is a mixin statement. void F(){} pragma(msg, __traits( compiles, mixin("F();") ) );//false Oh, now thats explains. I thought that a "mixin statement"

Re: __traits(compiles , mixin ... )

2017-10-25 Thread Adam D. Ruppe via Digitalmars-d-learn
tements or declarations. " When there's a closing ;, it is a mixin statement. void F(){} pragma(msg, __traits( compiles, mixin("F();") ) );//false

Re: __traits(compiles , mixin ... )

2017-10-25 Thread SrMordred via Digitalmars-d-learn
The semicolon there indicates it is a complete statement that does nothing, and that's no error. so why this line resolves to false? void F(){} pragma(msg, __traits( compiles, mixin("F();") ) );//false

Re: __traits(compiles , mixin ... )

2017-10-25 Thread SrMordred via Digitalmars-d-learn
On Wednesday, 25 October 2017 at 19:25:01 UTC, Adam D. Ruppe wrote: On Wednesday, 25 October 2017 at 19:12:02 UTC, SrMordred wrote: Maybe i´m tired already, but whats wrong here: pragma(msg, __traits( compiles, mixin("int x") ) ); You are missing a ; The mixin must compile as a

Re: __traits(compiles , mixin ... )

2017-10-25 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 25 October 2017 at 19:21:27 UTC, SrMordred wrote: mixin( "T();" ); Error: `structliteral` has no effect in expression `T()` The semicolon there indicates it is a complete statement that does nothing, and that's no error. If there's no ;, it is just an expression that must be so

Re: __traits(compiles , mixin ... )

2017-10-25 Thread SrMordred via Digitalmars-d-learn
On Wednesday, 25 October 2017 at 19:12:02 UTC, SrMordred wrote: Maybe i´m tired already, but whats wrong here: pragma(msg, __traits( compiles, mixin("int x") ) ); //output: false Or the original case I found: struct T{} pragma(msg, __traits( compiles, T() ) ); //true pragma(msg

Re: __traits(compiles , mixin ... )

2017-10-25 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 25 October 2017 at 19:12:02 UTC, SrMordred wrote: Maybe i´m tired already, but whats wrong here: pragma(msg, __traits( compiles, mixin("int x") ) ); You are missing a ; The mixin must compile as a full thing in context. Variable declarations need the ; to be complete.

__traits(compiles , mixin ... )

2017-10-25 Thread SrMordred via Digitalmars-d-learn
Maybe i´m tired already, but whats wrong here: pragma(msg, __traits( compiles, mixin("int x") ) ); //output: false

Re: __traits(compiles) + mixin

2013-03-05 Thread cal
On Tuesday, 5 March 2013 at 12:58:57 UTC, Timon Gehr wrote: Compiles as expected with DMD 2.060. It is probably a regression. Ah you're right, also with 2.061. I'll file.

Re: __traits(compiles) + mixin

2013-03-05 Thread Timon Gehr
On 03/05/2013 08:53 AM, cal wrote: I'm confused about this: import std.conv; void main() { enum s = "`1`.to!int;"; enum c = __traits(compiles, mixin("{auto a = new "~s~";}")); // line 1 mixin("auto a = "~s~";");

Re: __traits(compiles) + mixin

2013-03-05 Thread cal
On Tuesday, 5 March 2013 at 08:14:58 UTC, simendsjo wrote: Hmm.. And this also works: enum c = __traits(compiles, mixin("{auto a = new 1;}")); Something to do with CTFE combined with mixins? But it gets this right, in that c is false. I had thought that by wrapping the declaration

Re: __traits(compiles) + mixin

2013-03-05 Thread Andrej Mitrovic
On 3/5/13, cal wrote: > So why does this work: > > import std.conv; > > void main() > { > enum s = "`1`.to!int;"; > enum c = __traits(compiles, mixin("{auto x = "~s~";}")); // > true > } That's a function literal, i.e. an expression.

Re: __traits(compiles) + mixin

2013-03-05 Thread simendsjo
On Tuesday, 5 March 2013 at 08:04:12 UTC, Andrej Mitrovic wrote: On Tuesday, 5 March 2013 at 07:53:15 UTC, cal wrote: I'm confused about this: import std.conv; void main() { enum s = "`1`.to!int;"; enum c = __traits(compiles, mixin("{auto a = new "~s~";}&q

Re: __traits(compiles) + mixin

2013-03-05 Thread simendsjo
t 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?

Re: __traits(compiles) + mixin

2013-03-05 Thread cal
t;"; enum c = __traits(compiles, mixin("{auto x = "~s~";}")); // true }

Re: __traits(compiles) + mixin

2013-03-05 Thread Andrej Mitrovic
On Tuesday, 5 March 2013 at 07:53:15 UTC, cal wrote: I'm confused about this: import std.conv; void main() { enum s = "`1`.to!int;"; enum c = __traits(compiles, mixin("{auto a = new "~s~";}")); // line 1 mixin("auto a = "~s~";&quo

__traits(compiles) + mixin

2013-03-04 Thread cal
I'm confused about this: import std.conv; void main() { enum s = "`1`.to!int;"; enum c = __traits(compiles, mixin("{auto a = new "~s~";}")); // line 1 mixin("auto a = "~s~";"); /

Re: is(typeof(mixin(X))) and __traits(compiles, mixin(X))

2010-07-05 Thread Jacob Carlborg
On 2010-07-05 10.03, Jonathan M Davis wrote: Is there a way to use string mixins with is(typeof(X)) and/or __traits(compiles, X)? As far as I can tell, if I do either of the following is(typeof(mixin(X))) __traits(compiles, mixin(X)) it does not mixin the string and test that for compilation

is(typeof(mixin(X))) and __traits(compiles, mixin(X))

2010-07-05 Thread Jonathan M Davis
Is there a way to use string mixins with is(typeof(X)) and/or __traits(compiles, X)? As far as I can tell, if I do either of the following is(typeof(mixin(X))) __traits(compiles, mixin(X)) it does not mixin the string and test that for compilation but rather tests whether the mixin