www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 15229] New: BigInt(Range of chars) too

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 puremagic.com
          Reporter: bearophile_hugs 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.

--
Oct 21 2015