How to create strongly typed aliasses in D?

How to create a strict alias in D? Sort of:

alias euro = uint;
alias dollar = uint;

euro toEur(dollar pd) { ... }
dollar toDollar(euro pe) { ... }
+4
source share
2 answers

A strongly typed alias is actually a new type, so just use a simple structure:

struct euro {
     uint amount;
}

If you want it to be implicitly converted to and from uint, you can also add alias amount this;, but this makes typing easier, so you might not want to.

+3
source

You need a Typedef , which basically does what Adam offers.

+3
source

Source: https://habr.com/ru/post/1535759/


All Articles