hasDataMember and mixin inconsistency
Olivier Grant
olivier.grant at gmail.com
Mon Jan 28 01:55:43 PST 2013
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;" ?
>
> 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? And secondly wouldn't "x.M = y.M" take care of checking
that the member can be read and written to ? Also, doesn't your
solution require T to be default constructible ?
>> Using dmd 2.060 and command line "rdmd test.d", I get an
>> assertion fail on
>> both calls that check for a member "init" whether for int or
>> Test.
>
> Using 2.061 here.
Well that was the problem! I was still using 2.060 which seems to
have the bug. Now that I've moved to 2.061 everything works as
expected (your implementation and mine).
Thanks,
Olivier.
More information about the Digitalmars-d-learn
mailing list