std.typecons Typedef initializers?
Chris Katko
ckatko at gmail.com
Mon Apr 25 23:41:47 UTC 2022
On Monday, 25 April 2022 at 12:53:14 UTC, Mike Parker wrote:
> On Monday, 25 April 2022 at 08:54:52 UTC, Chris Katko wrote:
>> ````D
>> struct pair
>> {
>> float x,y;
>> }
>>
>> alias sPair = Typedef!pair; // pair of xy in screen space
>> coordinates
>> alias vPair = Typedef!pair; // pair of xy in viewport space
>> coordinates
>> //etc
>>
>>
>>
>> How do you initialize a typedef'd struct?
>
> ``d
> vPair v1 = vPair(pair(1f, 2f));
> ```
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
More information about the Digitalmars-d-learn
mailing list