char[] == null
Chris Wright via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Nov 19 07:15:36 PST 2015
On Thu, 19 Nov 2015 07:28:28 +0100, anonymous wrote:
> On 19.11.2015 06:18, Chris Wright wrote:
>> Just for fun, is an array ever not equal to itself?
>
> Yes, when it contains an element that's not equal to itself, e.g. NaN.
Exactly.
If NaN-like cases didn't exist, TypeInfo_Array could have an
optimization: if the pointers and lengths of its inputs were both equal,
the arrays are equal. But adding this optimization would result in
problematic behavior. Specifically:
auto a = [float.nan];
assert(a == a); // passes under proposed optimization, fails now
assert(a == a.dup); // fails under proposed optimization, fails now
More information about the Digitalmars-d-learn
mailing list