www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - pointers, null and Typedef...

reply "John Colvin" <john.loughran.colvin gmail.com> writes:
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?).
Aug 23 2013
parent reply "Paolo Invernizzi" <paolo.invernizzi gmail.com> writes:
On Friday, 23 August 2013 at 12:17:08 UTC, John Colvin wrote:
 so, here's the situation:
On 2.063.2 why not something like this: --- import std.typecons; alias T0 = Typedef!(void*, null, "T0"); alias T1 = Typedef!(void*, null, "T1"); static assert( ! is(T0 == T1)); struct A { T0 t; this(T0 init) { t = init; } } void foo(){ auto a = A(T0(null)); // auto b = A(T1(null)); Error! } --- Paolo
Aug 23 2013
parent reply "John Colvin" <john.loughran.colvin gmail.com> writes:
On Friday, 23 August 2013 at 18:58:49 UTC, Paolo Invernizzi wrote:
 On Friday, 23 August 2013 at 12:17:08 UTC, John Colvin wrote:
 so, here's the situation:
On 2.063.2 why not something like this: --- import std.typecons; alias T0 = Typedef!(void*, null, "T0"); alias T1 = Typedef!(void*, null, "T1"); static assert( ! is(T0 == T1)); struct A { T0 t; this(T0 init) { t = init; } } void foo(){ auto a = A(T0(null)); // auto b = A(T1(null)); Error! } --- Paolo
It's const(void*) not just void* Unfortunately that breaks it.
Aug 24 2013
parent "Paolo Invernizzi" <paolo.invernizzi gmail.com> writes:
On Saturday, 24 August 2013 at 09:19:14 UTC, John Colvin wrote:
 On Friday, 23 August 2013 at 18:58:49 UTC, Paolo Invernizzi 
 wrote:
 On Friday, 23 August 2013 at 12:17:08 UTC, John Colvin wrote:
 so, here's the situation:
On 2.063.2 why not something like this:
It's const(void*) not just void* Unfortunately that breaks it.
Sorry John, you are right, naturally. - Paolo
Aug 24 2013