On Monday, 25 April 2022 at 23:41:47 UTC, Chris Katko wrote:
So to use a typedef'd struct... I have to basically add the
original type on top of the typedef'd type every time? Surely
it's not this clunky?
I mean, why even use a typedef then. Why not use just pair,
sPair, vPair, etc as separate types with identical members and
cast as necessary? I'm not sure what the benefit typedef is
adding here.
Thanks
It could just be an oversight in implementation and worth
submitting an enhancement request on bugzilla.
Current implementation only defines a constructor that takes
rvalue of original type, while what it ought to be doing is
defining a variadic template constructor that would forward the
arguments to underlying type's constructor.
To be fair, as far as your example code goes, it'd almost be
easier to indeed simply duplicate the implementations, but have
the compiler do it for you, e.g. like this:
```d
enum Space
{
unspecified,
screen,
viewport,
}
struct TPair(Space space) { float x, y; }
alias Pair = Pair!(Space.unspecified);
alias sPair = Pair!(Space.screen);
alias vPair = Pair!(Space.viewport);
```