http://d.puremagic.com/issues/show_bug.cgi?id=2656


Andrei Alexandrescu <and...@metalanguage.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |and...@metalanguage.com


--- Comment #5 from Andrei Alexandrescu <and...@metalanguage.com> 2010-03-12 
09:26:28 PST ---
I have a simple suggestion - how about putting this in object.d:

template octal(string s)
{
    static assert(s.length > 0);
    static assert(s[0] >= '0' && s[0] < '8',
        "Incorrect character in octal constant: `" ~ s[0] ~ "'");
    if (s.length == 1)
    {
        enum ulong octal = s[0] - '0';
    }
    else
    {
        enum ulong octal = (s[0] - '0') + 8 * octal!(s[1 .. $]);
    }
}

unittest
{
    static assert(octal!"45" == 37);
    static assert(octal!"0" == 0);
    static assert(octal!"7" == 7);
    static assert(octal!"10" == 8);
}

Then we can deprecate octal constants by ruling integral literals starting with
0 illegal.

The code above has a few problems, e.g. hardcoding of "ulong" but they can be
easily solved by using and parsing the customary encodings (U, L, UL) at the
end of the string.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------

Reply via email to