Re: hasDataMember and mixin inconsistency

2013-01-29 Thread Olivier Grant
On Monday, 28 January 2013 at 20:21:19 UTC, Philippe Sigaud wrote: Just testing whether t.M can be assigned to something (ie, is it a value?) I use '_' as a variable name to indicate I don't care for it's precise name/value. It's just a placeholder. Ok, I must be missing something, why "t.D"

Re: hasDataMember and mixin inconsistency

2013-01-28 Thread Philippe Sigaud
>> Just testing whether t.M can be assigned to something (ie, is it a value?) >> I use '_' as a variable name to indicate I don't care for it's precise >> name/value. It's just a placeholder. > > > Ok, I must be missing something, why "t.D" or is this just a typo? Ark, typo, sorry about that. >

Re: hasDataMember and mixin inconsistency

2013-01-28 Thread Olivier Grant
On Sunday, 27 January 2013 at 16:51:26 UTC, Philippe Sigaud wrote: string hasDataMember( T )(string M ) { return " __traits(compiles, { Test t; auto _ = t.D; // reading t.M t." ~ M ~ " = t." ~ M ~ "; // assign to t.M })"; } What is the purpose of "auto _ = t.D;"

Re: hasDataMember and mixin inconsistency

2013-01-27 Thread Philippe Sigaud
>> string hasDataMember( T )(string M ) >> { >> return " __traits(compiles, { >> Test t; >> auto _ = t.D; // reading t.M >> t." ~ M ~ " = t." ~ M ~ "; // assign to t.M >> })"; >> } > > > What is the purpose of "auto _ = t.D;" ? Just testing whether t.M can be assign

Re: hasDataMember and mixin inconsistency

2013-01-27 Thread Olivier Grant
On Sunday, 27 January 2013 at 12:58:39 UTC, Philippe Sigaud wrote: I'd put the mixin externally: template hasDataMember( T, string M ) { mixin(" enum hasDataMember = __traits( compiles, ( ref T x, ref T y ){ x." ~ M ~ " = y." ~ M ~ "; } );"); } I've just tried that and i

Re: hasDataMember and mixin inconsistency

2013-01-27 Thread Philippe Sigaud
>> I'd put the mixin externally: >> >> template hasDataMember( T, string M ) >> { >>mixin(" >> >>enum hasDataMember = __traits( >> compiles, >> ( ref T x, ref T y ){ x." ~ M ~ " = y." ~ M ~ "; } >>);"); >> } > > > I've just tried that and it unfortunately does not work, the

Re: hasDataMember and mixin inconsistency

2013-01-27 Thread Artur Skawina
On 01/27/13 12:47, Olivier Grant wrote: > On Sunday, 27 January 2013 at 09:49:33 UTC, Philippe Sigaud wrote: >> You cannot write to .init, it's not a member. It's a built-in >> property, like .sizeof or .offsetof. > > Makes sense. It does, but apparently the compiler disagrees. >>> 2) Is there

Re: hasDataMember and mixin inconsistency

2013-01-27 Thread Olivier Grant
On Sunday, 27 January 2013 at 09:49:33 UTC, Philippe Sigaud wrote: Hi, If think in your code, your testing whether or a not a mixin("...") statement is valid D. Which it is. But what I'm surprised by is that the behavior of hasDataMember with my implementation works fine for all test cases e

hasDataMember and mixin inconsistency

2013-01-26 Thread Olivier Grant
Hi, First of all, I am very new to D as I've just been playing around with it for the last week, so I might be missing something very obvious. I'm trying to write a template that would allow me to determine if a struct or class has a data member with a specific name (similar to what the has