std.typecons Typedef initializers?
Paul Backus
snarwin at gmail.com
Mon Apr 25 13:07:24 UTC 2022
On Monday, 25 April 2022 at 08:54:52 UTC, Chris Katko wrote:
> ````D
> alias sPair = Typedef!pair; // pair of xy in screen space
> coordinates
> alias vPair = Typedef!pair; // pair of xy in viewport space
> coordinates
> //etc
> ````
This doesn't do what you think it does. Both `sPair` and `vPair`
are the same type. If you want to create two distinct `Typedef`s
from the same base type, you must use the optional `cookie`
argument, as shown in [the examples in the documentation:][1]
```d
alias MoneyEuros = Typedef!(float, float.init, "euros");
alias MoneyDollars = Typedef!(float, float.init, "dollars");
// The two Typedefs are _not_ the same type.
static assert(!is(MoneyEuros == MoneyDollars));
```
[1]:
https://phobos.dpldocs.info/std.typecons.Typedef.html#examples
More information about the Digitalmars-d-learn
mailing list