null == "" is true?
Salih Dincer
salihdb at hotmail.com
Fri Jul 15 06:38:58 UTC 2022
On Tuesday, 12 July 2022 at 22:58:32 UTC, Steven Schveighoffer
wrote:
> ```d
> string a = "abcabc";
> assert(a[0 .. 3] == a[3 .. $])
> assert(a[0 .. 3] !is a[3 .. $])
> ```
>
> The point is, `==` compares *value*, `is` always compares
> *identity*.
Consider null type array which is a related topic but it cannot
get a null element! The first is ok, but the second is legal. So
no effect, is it normal?
```d
auto p = [ null, null ];//*
assert(
is(typeof(null)[] :
typeof(p)
)
); /* and it has two(2) elements */
p ~= null; // okay
assert(p.length == 3); // true
p ~= []; // legal (no error)
assert(p.length != 4); // what! (no effect)
assert(p[0] == []); // true
assert([] == null); // right on
import std.stdio;
typeid(p).write(": ", p.length);
writeln("->", []); // typeof(null)[]: 3->[]
```
SDB at 79
More information about the Digitalmars-d-learn
mailing list