On Tuesday, 30 March 2021 at 13:28:55 UTC, novice3 wrote:


This messages dont help me understand, which type should i use.
What i should change?
Or Typedef template should be changes?

From the docs:

"Unlike the alias feature, Typedef ensures the two types are not considered as equals.
Parameters:"

https://dlang.org/phobos/std_typecons.html#Typedef


Any Typedef alternatives?

If you want your new type to be interchangeable with another, the straightforward way is just to use an alias. Buf if you need a more concrete type, you can use alias this in a struct:

import std.stdio;

struct MyType {
    void* wrapped;
    alias wrapped this;
}


void doSomething(void* t) {
    writeln(*(cast(int*)t));
}

void main() {
    int i = 20;
    MyType mt = MyType(&i);
    doSomething(mt);
}

Reply via email to