[Issue 17616] New: makeIndex cannot fully use range of index type

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Fri Jul 7 03:29:04 PDT 2017


https://issues.dlang.org/show_bug.cgi?id=17616

          Issue ID: 17616
           Summary: makeIndex cannot fully use range of index type
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: phobos
          Assignee: nobody at puremagic.com
          Reporter: code at dawg.eu

cat > bug.d << CODE
void main()
{
    import std.algorithm, std.range;

    ubyte[256] index = void;
    iota(256).makeIndex(index[]);
    assert(index[].equal(iota(256)));
}
CODE
dmd -run bug
----
object.Exception@/usr/include/dmd/phobos/std/algorithm/sorting.d(997): Cannot
create an index with element type ubyte with length 256.
----

The maximum index value for a range of length 256 is 255, which fits nicely
into a ubyte.
makeIndex should support converting a full range of e.g. ubyte[256] or
ushort[65536] into an index of ubyte[256] or ushort[65536] as it's a nice way
to obtain a bijective inverse mapping of such a range.

--


More information about the Digitalmars-d-bugs mailing list