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))