Currently, it is impossible to special-case comparisons with null. If instead null had its own type, one could allow direct comparisons between user-defined types and null, instead of supporting comparison with any and all void*s.
For structs, such a comparison function could then be used for both 'foo == null' and 'foo is null'. For classes, neither likely makes sense.
Comment #1 by code — 2011-10-07T09:08:52Z
Also if you pass null to a template it completely looses its implict conversion abilites. See following example.
void foo(Object o){
}
void fooHelper(T)(T o){
foo(o);
}
void main(string[] args){
fooHelper(null); //can not implicitly convert void* to Object
}
This also stops std.conv.emplace to work correctly with constructors you want to pass null to.
(In reply to comment #1)
> Also if you pass null to a template it completely looses its implict conversion
> abilites. See following example.
>
> void foo(Object o){
> }
>
> void fooHelper(T)(T o){
> foo(o);
> }
>
> void main(string[] args){
> fooHelper(null); //can not implicitly convert void* to Object
> }
>
> This also stops std.conv.emplace to work correctly with constructors you want
> to pass null to.
This is still true if 'Object' is replaced by Object[], 'null' is replaced by '[]' and 'void*' by 'void[]'. Therefore, '[]' needs an own type too.
(I think it is the same issue, or should I file a separate bug for it?)