pointers, null and Typedef...

John Colvin john.loughran.colvin at gmail.com
Fri Aug 23 05:17:03 PDT 2013


so, here's the situation:

current old code has:

typedef const(void*) T0, T1;

which is of course deprecated.

context that needs to work:

struct A
{
     T0 t;
     this(T0 init)
     {
         t = init;
     }
}

Also, I need type-safety. is(T0 == T1) *must* be false.

I have a modified Typedef I'm using to get things started, 
allowing Typedef!(const(void*), const(void*).init, "T0") to work 
at all:

struct Typedef(T, T init = T.init, string cookie=null)
{
     static if(init != T.init)
     {
         private T Typedef_payload = init;
     }
     else
     {
         private T Typedef_payload;
     }

     this(T initial)
     {
	Typedef_payload = initial;
     }

     this(typeof(this) initial)
     {
	Typedef_payload = initial.Typedef_payload;
     }

     mixin Proxy!(Typedef_payload);
}

but that doesn't get me all of the way, there's still no way I 
can see to get the t = init to work. I wish there was some way to 
call a constructor on a object after it is declared (perhaps with 
the same rules as const initialisation?).


More information about the Digitalmars-d-learn mailing list