[Issue 12940] New: std.bigint.Bigint.toSize_t too, and alternative API suggestion

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Wed Jun 18 02:49:49 PDT 2014


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

          Issue ID: 12940
           Summary: std.bigint.Bigint.toSize_t too, and alternative API
                    suggestion
           Product: D
           Version: D2
          Hardware: x86
                OS: Windows
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: Phobos
          Assignee: nobody at puremagic.com
          Reporter: bearophile_hugs at eml.cc

std.bigint.Bigint has toInt/toLong methods:

const pure long toLong();
    Returns the value of this BigInt as a long, or +- long.max if outside the
representable range.

const pure int toInt();
    Returns the value of this BigInt as an int, or +- int.max if outside the
representable range.


I think it's also useful a "toSize_t" method, to use bigInts for array indexes.

Another unrelated idea is to change the behavour for the cases when the value
is outside the representable range, returning a Nullable!int, Nullable!long or
Nullable!size_t that is null in case of overflow.

(In general I think Phobos should start using std.typecons.Nullable more
often.)

--


More information about the Digitalmars-d-bugs mailing list