defect when using 'alias this' in a struct?
Kieron Brown
kieron_brown at hotmail.com
Mon Aug 30 10:12:00 PDT 2010
I have used alias this and found odd behaviour in complex code.
I tracked the problem down and was able to replicate it
with a much simpler case as given below.
I'm new to D (but have read TDPL).
Is this my mis-understanding or a defect?
Many thanks, Kieron
----- self contained d sample starts -----
import std.stdio, std.math;
void main()
{
auto p = Test(0.5, 0.5);
assert(0.5 == p.a); // ok
assert(0.5 == p.b); // ok
Test q;
// q = Test(0.5, 0.5);
//
// the above line gave same
// error when subst for
// the line below
q = p;
if (isNaN(q.b))
printf("problem replicated\n");
assert(0.5 == q.a); // ok
assert(0.5 == q.b); // this fails
}
struct Test
{
double a;
double b;
alias a this;
}
----- end of file -----
More information about the Digitalmars-d-learn
mailing list