Bug 12940 – std.bigint.Bigint.toSize_t too, and alternative API suggestion

Status
NEW
Severity
enhancement
Priority
P4
Component
phobos
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2014-06-18T09:49:49Z
Last change time
2024-12-01T16:21:28Z
Assigned to
No Owner
Creator
bearophile_hugs
See also
https://issues.dlang.org/show_bug.cgi?id=15212
Moved to GitHub: phobos#9635 →

Comments

Comment #0 by bearophile_hugs — 2014-06-18T09:49:49Z
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.)
Comment #1 by schveiguy — 2017-03-31T23:13:11Z
trivial to implement, but not trivial to decide whether this should happen. cast(size_t)someBigInt works, so I'm not sure it's needed in any case.
Comment #2 by robert.schadek — 2024-12-01T16:21:28Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/phobos/issues/9635 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB