if(arr) now a warning

biozic via Digitalmars-d digitalmars-d at puremagic.com
Fri Apr 10 01:53:28 PDT 2015


On Friday, 10 April 2015 at 08:38:00 UTC, Jacob Carlborg wrote:
> On 2015-04-09 22:59, Steven Schveighoffer wrote:
>
>> As usual with changes of this nature, there are differing 
>> opinions, and
>> differing styles. I personally never use null as a special 
>> value for an
>> array, but others do. They use if(arr) to actually mean 
>> if(arr.ptr). For
>> these cases, the update will cause some amount of busywork 
>> changing
>> these checks.
>>
>> But when updating Phobos to comply with this change, we found 
>> several
>> actual incorrect usages. So I think the change is worth it, 
>> and not much
>> busywork. YMMV.
>>
>> What do you think?
>
> I'm wondering how often in practice .ptr is not null but the 
> array is empty.

When you remove elements from arrays: you end up with slices of 
length 0 that have a non-null .ptr. Not that rare.


More information about the Digitalmars-d mailing list