Quick question regarding dynamic array deletions
Dennis
dkorpel at gmail.com
Sun Sep 1 18:42:54 UTC 2019
On Sunday, 1 September 2019 at 18:26:20 UTC, WhatMeWorry wrote:
> Maybe my question is when would be want to use 3) without also
> adjusting the .ptr ?
It matters when casting to a boolean, since an empty array with a
non-null pointer is still `true` while an array with null pointer
casts to `false`. This could be useful when you want to
distinguish 'no array' and an empty array.
For example:
```
int[] getList(); // might fail
void main() {
if (auto list = getList) {
writeln(list); // could be an empty list
} else {
error("could not retrieve list"); // must be 'null' list
}
}
```
More information about the Digitalmars-d-learn
mailing list