Bug 17616 – makeIndex cannot fully use range of index type
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2017-07-07T10:29:04Z
Last change time
2018-01-05T13:29:57Z
Assigned to
No Owner
Creator
Martin Nowak
Comments
Comment #0 by code — 2017-07-07T10:29:04Z
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.
Comment #1 by github-bugzilla — 2017-07-07T13:14:54Z