D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 6808 - string to BigInt using std.conv.to
Summary: string to BigInt using std.conv.to
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: No Owner
URL:
Keywords: patch, rejects-valid
Depends on:
Blocks:
 
Reported: 2011-10-12 16:18 UTC by bearophile_hugs
Modified: 2012-02-23 14:31 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description bearophile_hugs 2011-10-12 16:18:01 UTC
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))