default '==' on structs
spir
denis.spir at gmail.com
Wed Feb 2 10:41:37 PST 2011
On 02/02/2011 07:05 PM, bearophile wrote:
> spir:
>
>> * The issue reported is about '==' on structs not using member opEquals when
>> defined, instead performing bitwise comparison. This is not my case: Lexeme
>> members are plain strings and an uint. They should just be compared as is.
>> Bitwise comparison should just work fine.
>> Also, this issue is marked solved for dmd 2.037 (I use 2.051).
>
> Lars is right, the == among structs is broken still:
>
> struct Foo { string s; }
> void main() {
> string s1 = "he";
> string s2 = "llo";
> string s3 = "hel";
> string s4 = "lo";
> auto f1 = Foo(s1 ~ s2);
> auto f2 = Foo(s3 ~ s4);
> assert((s1 ~ s2) == (s3 ~ s4));
> assert(f1 == f2);
> }
Thank you, this helps much. I don't get the details yet, but think some similar
issue is playing a role in my case. String members of the compared Lexeme
structs are not concatenated, but one of them is sliced from the scanned source.
If I dup'ed instead of slicing, this would create brand new strings; thus '=='
performing bitwise comp should run fine, don't you think? I'll try in a short
while.
Do you know more about why/how the above fails?
Denis
--
_________________
vita es estrany
spir.wikidot.com
More information about the Digitalmars-d-learn
mailing list