Does D have 'newtype'?

后端 未结 2 1010
夕颜
夕颜 2021-02-14 17:22

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 17:59

    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.

提交回复
热议问题