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.

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.

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.

Structs are compared *bitwise*!
When you dup your pointer is different and thus the structs are different.

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.

Structs are compared *bitwise*!
When you dup your pointer is different and thus the structs are different.

I believe the question was *why* things are this way. I think it's weird.

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.

Structs are compared *bitwise*!
When you dup your pointer is different and thus the structs are
different.

I believe the question was *why* things are this way. I think it's weird.

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.

Structs are compared *bitwise*!
When you dup your pointer is different and thus the structs are different.

Yes, I intentionally duped the string to make sure they're not using the
same memory. I was thinking of something like a transitive ==.

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.

Structs are compared *bitwise*!

Not in D2, any more. If a member has an opEquals, it's compared using ==.

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.

Structs are compared *bitwise*!

Not in D2, any more. If a member has an opEquals, it's compared using ==.

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.