Derived type

Basile B. b2.temp at gmx.com
Tue Mar 30 21:53:34 UTC 2021


On Tuesday, 30 March 2021 at 19:47:41 UTC, novice2 wrote:
> My tries to make template for struct and alias this:
>
> ////// variant 1
> template Typedef(alias Tnew, Tbase)
> {
>   struct Tnew
>   {
>     Tbase payload;
>     alias payload this;
>   }
> }
>

you must give a name to the template specialization, using alias 
[1], also the TypeDef declaration can be highly simplified:

---
struct Typedef(TBase)
{
    TBase payload;
    alias payload this;
}

alias Xobj = Typedef!(void*);

void foo (Xobj obj) {}
---


[1]: https://dlang.org/spec/declaration.html#alias



More information about the Digitalmars-d-learn mailing list