[Issue 6808] New: string to BigInt using std.conv.to

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Oct 12 16:18:51 PDT 2011


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

           Summary: string to BigInt using std.conv.to
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: Phobos
        AssignedTo: nobody at puremagic.com
        ReportedBy: bearophile_hugs at eml.cc


--- Comment #0 from bearophile_hugs at eml.cc 2011-10-12 16:18:01 PDT ---
For generic code, and to run functions with both integers and bigintegers, I'd
like to use bigintegers in many of the situations where I use ints (I don't
expect to use bigintegers everywhere, like as array indexes).

The BigInt struct allows the conversion of a string to a BigInt, but you have
to use a specific syntax for that:


import std.conv, std.bigint;
void main() {
    string s = "101";
    auto i1 = to!int(s); // OK
    auto i2 = BigInt(s); // OK
}



So if possible I'd like to use the normal to! syntax to convert a string to
BigInt:

import std.conv, std.bigint;
void main() {
    string s = "101";
    auto i3 = to!BigInt(s); // Error
}


Is this possible?


With DMD 2.056head the second program gives:

...dmd2\src\phobos\std\conv.d(227): Error: template std.conv.toImpl(T,S) if
(isImplicitlyConvertible!(S,T)) toImpl(T,S) if (isImplicitlyConvertible!(S,T))
matches more than one template declaration,
...dmd2\src\phobos\std\conv.d(434):toImpl(T,S) if
(!isImplicitlyConvertible!(S,T) && is(T == struct) && is(typeof(T(src)))) and
...dmd2\src\phobos\std\conv.d(1726):toImpl(T,S) if (isDynamicArray!(S) &&
isSomeString!(S) && !isSomeString!(T))

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


More information about the Digitalmars-d-bugs mailing list