https://issues.dlang.org/show_bug.cgi?id=9797

Jonathan M Davis <issues.dl...@jmdavisprog.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |issues.dl...@jmdavisprog.co
                   |                            |m

--- Comment #6 from Jonathan M Davis <issues.dl...@jmdavisprog.com> ---
I would point out that while to!int("0x123"); isn't going to work,
to!int("123", 16); will. e.g.

    import std.conv;

    void main()
    {
        auto str = to!string(42, 16);
        assert(str == "2A", str);
        auto i = to!int(str, 16);
        assert(i == 42);
    }

So, if you check for 0x and strip it off before feeding the string to to!int,
then it will do the conversion. It just won't work with the prefix on it. And
while having to!int check for the prefix as well as anything else that's valid
in a numeric literal in D might be nice in some cases, it would slow down
to!int for everything else, which really isn't a good tradeoff given how much
to!int is used. A conversion function specifically for literals might make
sense, but I have to concur that doing it with std.conv.to isn't worth it.

--

Reply via email to