The more interesting question
Steven Schveighoffer
schveiguy at yahoo.com
Wed May 16 10:38:02 PDT 2012
On Wed, 16 May 2012 13:17:17 -0400, Gor Gyolchanyan
<gor.f.gyolchanyan at gmail.com> wrote:
> On Wed, May 16, 2012 at 9:07 PM, Steven Schveighoffer
> <schveiguy at yahoo.com>wrote:
>
>> On Wed, 16 May 2012 12:21:27 -0400, Gor Gyolchanyan <
>> gor.f.gyolchanyan at gmail.com> wrote:
>>
>>
>>> if("" != []) assert("".length != 0);
>>>
>>> Will this fail?
>>>
>>
>> No. Ambiguities only come into play when you use 'is'. I highly
>> recommend not using 'is' for arrays unless you really have a good
>> reason,
>> since two slices can be 'equal' but 'point at different instances'.
>>
>> For example:
>>
>> auto str = "abcabc";
>> assert(str[0..3] == str[3..$]); // pass
>> assert(str[0..3] is str[3..$]); // fail
>>
>> which is very counterintuitive.
>>
>> -Steve
>>
>
> Doesn't assert("".length != 0) look extremely counter-intuitive?
That assert would always fail, if the if statement would ever succeed. It
doesn't look counter-intuitive, it looks like a bug!
You basically said:
if(0) assert("".length != 0);
-Steve
More information about the Digitalmars-d
mailing list