[Issue 15229] New: BigInt(Range of chars) too
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Wed Oct 21 00:37:10 PDT 2015
https://issues.dlang.org/show_bug.cgi?id=15229
Issue ID: 15229
Summary: BigInt(Range of chars) too
Product: D
Version: D2
Hardware: x86_64
OS: Windows
Status: NEW
Severity: enhancement
Priority: P1
Component: phobos
Assignee: nobody at puremagic.com
Reporter: bearophile_hugs at eml.cc
This is a slow and naive function to reverse a BigInt:
import std.bigint: BigInt;
import std.conv: to;
import std.conv: text;
import std.range: retro;
BigInt rev(in BigInt n) {
return n.text.retro.text.BigInt;
}
void main() {
assert(125.BigInt.rev == 521);
}
But I'd like to avoid the second text conversion, and to write:
BigInt rev2(in BigInt n) {
return n.text.retro.BigInt;
}
In general in Phobos there are many functions (and constructors) that could and
sometimes should be range-ifed. An obvious one is to make std.conv.to!() accept
a lazy input too.
--
More information about the Digitalmars-d-bugs
mailing list