Why isn't == used to compare structs

Manuel =?ISO-2022-JP?B?SxskKEQrUxsoQm5pZw==?= manuelk89 at gmx.net
Mon Feb 8 04:35:31 PST 2010


Am Mon, 08 Feb 2010 12:19:12 +0100
schrieb Jacob Carlborg <doob at me.com>:

> struct String
> {
> 	char[] data;
> }
> 
> void main ()
> {
> 	auto foo = String("foo");
> 	auto bar = String("foo".dup);
> 
> 	assert(bar == foo);
> }
> 
> Why isn't == used to compare the struct members in the code above? I 
> mean, if I compare the structs with == it could also use == to
> compare the members. If I use "is" to compare the structs it could
> use "is" to compare them members.

How should == be used for this struct?

struct Foo
{
	union
	{
		char[] dataA;
		long dataB;
	}
}

Foo a,b;

a.dataA = "abc";
b.dataA = "abc".dup;

Now a.dataA == b.dataA, but a.dataB != b.dataB.


More information about the Digitalmars-d-learn mailing list