www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 12940] New: std.bigint.Bigint.toSize_t too, and alternative


          Issue ID: 12940
           Summary: std.bigint.Bigint.toSize_t too, and alternative API
           Product: D
           Version: D2
          Hardware: x86
                OS: Windows
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: Phobos
          Assignee: nobody puremagic.com
          Reporter: bearophile_hugs 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

Jun 18 2014