On Aug 23, 2012, at 4:25 AM, bearophile <[email protected]> wrote:
> Sean Kelly: > >> Gotcha. Despite it being something I'd use regularly, I wouldn't want this >> in Phobos because it seems like it could cause maintenance problems. I'd >> rather explicitly cast to ubyte as a way to flag that I was doing something >> potentially unsafe. > > What's unsafe in what I have presented? The constructor verifies every char > to be in 7 bits, and then you use the new type safely. No casts, and no need > to flag something as unsafe. > > This usage of types to denote capabilities is quite common in functional > languages, see articles I've recently linked here as: > http://tomasp.net/blog/type-first-development.aspx So it throws an exception if there are non-ASCII characters in the range? Is this really better than just casting the input array to ubyte?
