Forbid dynamic arrays in boolean evaluation contexts

Phil Lavoie maidenphil at hotmail.com
Mon Mar 25 10:34:23 PDT 2013


On Monday, 25 March 2013 at 17:25:13 UTC, Timon Gehr wrote:
> On 03/25/2013 06:13 PM, Phil Lavoie wrote:
>> ...
>>
>> However, testing for null is kinda useful :)
>> ...
>
> It is currently basically useless for array slices, because 
> relying on it is brittle.

Well, since they CAN be null, it is at least useful in contracts 
programming.
void foo( int[] zeSlice ) in {
  assert( zeSlice !is null, "passing null slice" )
} body {

}

Also, imagine, for some reasons, you have that
string[ ( int[] ) ] mapOfSlices;
...
//initialize all strings, but make sure their corresding slices 
are null, because an empty slice has a different meaning.

auto aSlice = mapOfSlices.get( "toto", null );

Still comparing against null, since it has a different meaning, 
maybe null means not found and empty means found but without 
value.


More information about the Digitalmars-d mailing list