Does D have 'newtype'?

后端 未结 2 692
太阳男子
太阳男子 2021-02-14 17:37

Does D have \'newtype\' (as in Haskell).

It\'s a naive question, as I\'m just skimming D, but Google didn\'t turn up anything useful.

In Haskell this is a way of

2条回答
  •  遥遥无期
    2021-02-14 18:15

    Funny, as he_the_great mentions, D1 had a strong typedef but noone used it, possibly because it was impossible to customize the exact semantics for each case. Possibly the simplest way to handle this situation, at least for primitive types, is to include a mixin template somewhere in Phobos that allows you to forward all operators but have the boilerplate to do this automatically generated via the mixin. Then you'd just create a wrapper struct and be all set.

提交回复
热议问题