Bug 4444 – Cannot index built-in array with expression tuple
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2010-07-10T11:52:00Z
Last change time
2014-02-15T02:44:16Z
Keywords
patch, spec
Assigned to
nobody
Creator
rsinfu
Comments
Comment #0 by rsinfu — 2010-07-10T11:52:05Z
Expression tuples cannot be used for indexing built-in arrays:
--------------------
import std.typetuple;
void main()
{
alias TypeTuple!(1) index;
auto arr = new int[4];
auto x = arr[index]; // error
}
--------------------
% dmd -o- -c test
test.d(6): Error: cannot implicitly convert expression (tuple(1)) of type (int) to uint
--------------------
While overloaded opIndex accepts expression tuple.
--------------------
import std.typetuple;
void main()
{
alias TypeTuple!(1) index;
S s;
auto x = s[index]; // okay
}
struct S
{
size_t opIndex(size_t i) { return i; }
}
--------------------