[Issue 14569] New: BigInt is not compatible with the type of immutable (char) and has a problem when converting from a type immutable(char)

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Sun May 10 20:28:37 PDT 2015


https://issues.dlang.org/show_bug.cgi?id=14569

          Issue ID: 14569
           Summary: BigInt is not compatible with the type of immutable
                    (char) and has a problem when converting from a type
                    immutable(char)
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: Phobos
          Assignee: nobody at puremagic.com
          Reporter: dennis.m.ritchie at mail.ru

In my opinion, this should be corrected:

import std.stdio : writeln;
import std.conv : to, text;
import std.bigint : BigInt;

void main() {

    BigInt twoInThousand = 2.to!BigInt ^^ 1000;

    string s = twoInThousand.text;

    BigInt sum1, sum2, sum3, sum4;
    foreach (e; s) {
        // sum1 += e.to!BigInt; // Error: template instance
        // std.conv.to!(BigInt).to!(immutable(char)) error instantiating

        sum2 += e.to!int; // wrong
        sum3 += e.to!uint; // wrong
        sum4 += e.text.to!BigInt; // OK
    }

    writeln(sum2); // 15862 // wrong
    writeln(sum3); // 15862 // wrong
    writeln(sum4); // 1366 // OK
}

--


More information about the Digitalmars-d-bugs mailing list