Own type for null?

Timon Gehr timon.gehr at gmx.ch
Wed Oct 26 09:19:42 PDT 2011


On 10/26/2011 05:55 PM, Benjamin Thaut wrote:
> Am 26.10.2011 10:56, schrieb Timon Gehr:
>> On 10/26/2011 07:49 AM, Benjamin Thaut wrote:
>>> I recently tried to replace the deprecated overloading of new and delete
>>> and came across a serious issue. You can not use std.conv.emplace with
>>> null. If you pass null to it, null loses it's implicit casting
>>> cabablities and just becomes a void*.
>>> This issue pretty much exists with every template. As soon as you pass
>>> null to a template (compile time) information gets lost.
>>>
>>> Besides fixing std.conv.emplace it could be really handy to be able to
>>> check for a null-type at compile time for example with non-nullable
>>> types.
>>>
>>> There is already a enhancement reqeust in bugzilla since January but it
>>> didn't get much attention yet:
>>> http://d.puremagic.com/issues/show_bug.cgi?id=5416
>>>
>>> Would this be a worthwile improvement for the langauge?
>>
>> ++vote.
>>
>> We also need an own type for the empty array literal '[]' btw.
>
> Do you have an example where a own type for [] would be usefull?
>

It is the same rationale as the one for null

Eg:

class Class{
     this(int,string,double[]) {}
}

auto New(T,A...)(A args) {
     return new T(args);
}

void main(){
     auto a = new Class(1,"hi",[]); // fine
     auto b = New!Class(1,"hi",[]); // would require an own type
}


More information about the Digitalmars-d mailing list