www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 6808] New: string to BigInt using std.conv.to

reply d-bugmail puremagic.com writes:
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 puremagic.com
        ReportedBy: bearophile_hugs eml.cc



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: -------
Oct 12 2011
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6808


Kenji Hara <k.hara.pg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch, rejects-valid
           Severity|enhancement                 |normal



https://github.com/D-Programming-Language/phobos/pull/292

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 13 2011
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6808


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |clugdbug yahoo.com.au
         Resolution|                            |FIXED



Fixed some time ago.
https://github.com/D-Programming-Language/phobos/commit/b85e583ad68dcee15c2be3030f3f7090f727e601

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