Bug 6808 – string to BigInt using std.conv.to

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2011-10-12T16:18:00Z
Last change time
2012-02-23T14:31:12Z
Keywords
patch, rejects-valid
Assigned to
nobody
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2011-10-12T16:18:01Z
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))
Comment #1 by k.hara.pg — 2011-10-13T20:00:15Z
Comment #2 by clugdbug — 2012-02-23T14:31:12Z