digitalmars.D.bugs - [Issue 12940] New: std.bigint.Bigint.toSize_t too, and alternative
- via Digitalmars-d-bugs (28/28) Jun 18 2014 https://issues.dlang.org/show_bug.cgi?id=12940
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 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 often.) --
Jun 18 2014