Distinguish between a null array and an empty array
Dukc
ajieskola at gmail.com
Wed May 27 01:49:56 UTC 2020
On Sunday, 24 May 2020 at 12:29:23 UTC, bauss wrote:
> Dang, that sucks there is no proper way and I would say that's
> a big flaw of D.
>
> Because what I need it for is for some data serialization but
> if the value is an empty array then it should be present and if
> it's null then it should not be present.
>
> Since null is used to say "ignore this" in the data
> serialization.
>
> Oh well.
If you want to avoid the memory cost of `Nullable`, I think you
could still have a special value for "no data". But I wouldn't
use D `null` for it, because it's so common for it to be used for
empty values. Instead, I'd define a small data section somewhere.
You test whether the array points to it (`&arr[0] ==
&nullSection[0]`), and if, it means no data.
More information about the Digitalmars-d-learn
mailing list