On 2/6/18 8:06 PM, Luís Marques wrote:
On Wednesday, 7 February 2018 at 00:24:26 UTC, H. S. Teoh wrote:
I really like your .nx idea!  It neatly sidesteps the nonsensical mandatory casts and on top of that documents intent (the .nx being a telltale sign of truncation -- much better than arbitrary implicit rules).  I think I'll adopt it in some form in my code, to make dealing with narrow ints saner.  I don't know what your .nx type does, but for my purposes I'll probably just have a thin wrapper around byte/ubyte/etc. with overloaded arithmetic operators that perform the requisite casts.

Yeah, it's just a thin wrapper. I implemented just enough to cover my use cases but just in case it's useful to you or someone else, here goes my implementation...

private struct NX(T)
{
...


I think this would be a good Phobos addition. std.typecons?

-Steve

Reply via email to