Implicit enum conversions are a stupid PITA

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Thu Mar 25 14:52:29 PDT 2010


On 03/25/2010 04:32 PM, Adam D. Ruppe wrote:
> On Thu, Mar 25, 2010 at 05:12:07PM -0400, bearophile wrote:
>> It needs many more unittests, to tests all the bounds, corner cases, etc. They also have to test that the code actually asserts when the inputs are wrong in various ways. This is how I test my D code.
>
> Yeah, you're right on a few counts. The template there actually fails on
> any string with length>  2. I rewrote it just now to do CTFE too to get
> around it. I also let underscores into the string in my new version, and
> switched the uints to ulongs so we can get bigger literals before needing
> strings.
>
> It seems to work well. Here's my new code:

It does work well, but there's one more issue: the type of octal!x is 
always ulong. To make the code industrial strength, you should observe 
the usual D rules:

* if it fits in an int it has type int, otherwise it has type long

* the suffixes U, u, and L should be observed

If you make these changes I'll commit your code in std.conv with credit.


Andrei



More information about the Digitalmars-d mailing list