Empty VS null array?

H. S. Teoh hsteoh at quickfur.ath.cx
Thu Oct 17 16:32:46 PDT 2013


On Fri, Oct 18, 2013 at 01:27:33AM +0200, Adam D. Ruppe wrote:
> On Thursday, 17 October 2013 at 23:12:03 UTC, ProgrammingGhost
> wrote:
> >is null still treats [] as null.
> 
> blah, you're right. It will at least distinguish it from an empty
> slice though (like arr[$..$]). I don't think there's any way to tell
> [] from null except typeof(null) at all. At runtime they're both the
> same: no contents, so null pointer and zero length.

I think it's a mistake to rely on the distinction between null and
non-null but empty arrays in D. They should be regarded as
implementation details that user code shouldn't depend on. If you need
to distinguish between arrays that are empty and arrays that are null,
consider using Nullable!(T[]) instead.


T

-- 
Curiosity kills the cat. Moral: don't be the cat.


More information about the Digitalmars-d mailing list