Creating a new type, to get strong-ish type checking and restrict usage to certain operations, using struct perhaps
Ali Çehreli via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Fri Jul 21 12:09:25 PDT 2017
On 07/21/2017 11:49 AM, Cecil Ward wrote:
> I was think about how to create a new type that holds packed bcd values,
> of a choice of widths, that must fit into a uint32_t or a uint64_t (not
> really long multi-byte objects). I am not at all sure how to do it. I
> thought about using a templated struct to simply wrap a uint of a chosen
> width, and perhaps use alias this to make things nicer.
>
Andrei's checkedint may give ideas:
https://dlang.org/phobos/std_experimental_checkedint.html
He presented it in this talk:
http://dconf.org/2017/talks/alexandrescu.html
... which is missing the following video link:
https://www.youtube.com/watch?v=29h6jGtZD-U
... which has a longer version:
https://www.youtube.com/watch?v=es6U7WAlKpQ
Ali
More information about the Digitalmars-d-learn
mailing list