On Tuesday, 30 March 2021 at 13:43:52 UTC, Mike Parker wrote:
the straightforward way is just to use an alias.

i cant use alias - compiler cannot distinguish base type and alias, and cannot catch programmer errors

Buf if you need a more concrete type, you can use alias this in a struct:
I think Typedef template should do this struct for me.

Thanks Mike, this way is what i wanted

  struct Xobj {
    private void* payload;
    alias payload this;
  }

  Xobj good;
  foo(good);            //nice
  foo(cast(Xobj)null);  //explicit cast allowed - nice
foo(null); //no implicit cast disallowed - compiler error - nice

  void* bad;
  foo(bad);             //compiler distinguish type - error - nice


I think Typedef template should do this struct for me.

Problem with Typedef template - code
  alias Xobj = Typedef!(void*)
not generate struct named "Xobj",
but struct named "Typedef!(void*, null, null)".
This makes compiler error messages unusable.

I will try to make template for struct. But template is black magic for me :)

Reply via email to