Creating a new type, to get strong-ish type checking and restrict usage to certain operations, using struct perhaps
Moritz Maxeiner via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Jul 22 01:34:03 PDT 2017
On Saturday, 22 July 2017 at 06:08:59 UTC, Cecil Ward wrote:
> On Saturday, 22 July 2017 at 03:18:29 UTC, Cecil Ward wrote:
>> [...]
>
> I saw David Nadlinger's units package. I'd like to know how the
> strong typing works.
By wrapping in structs and overloading operators [1][2][3][4].
[1]
https://github.com/klickverbot/phobos/blob/units/std/units.d#L727
[2]
https://github.com/klickverbot/phobos/blob/units/std/units.d#L736
[3]
https://github.com/klickverbot/phobos/blob/units/std/units.d#L756
[4]
https://github.com/klickverbot/phobos/blob/units/std/units.d#L765
More information about the Digitalmars-d-learn
mailing list