Why typedef's shouldn't have been removed :(

Steven Schveighoffer schveiguy at yahoo.com
Fri May 11 12:04:52 PDT 2012


On Fri, 11 May 2012 14:56:45 -0400, Mehrdad <wfunction at hotmail.com> wrote:

> Okay, I just tried changing "alias void*" to "alias Typedef(void*)", and  
> also "alias HANDLE" to "alias Typedef(HANDLE)", etc.
>
> First error I got?
>
> 	HMODULE hAdvapi32 = null;
> 	...\src\phobos\std\internal\windows\advapi32.d(32):
> 	Error:
> 	cannot implicitly convert expression (null) of type typeof(null) to  
> Typedef!(Typedef!(void*,null),Typedef(null))
>
>
> Which makes sense, except that I'm not sure how to solve it correctly in  
> general...
> I think it's a bigger problem than it looks, since 'null' would need to  
> be convertible to everything that's nullable...

This is a frequent problem with null.  Since null is its own type now, it  
doesn't play nice with custom types, only builtins enjoy special treatment  
for null.

> ideas?

probably something like opBool:

struct S
{
   int x;
   static S opNull() { return S(0);}
}

S s = null; // equivalent to S(0);

-Steve


More information about the Digitalmars-d mailing list