D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 4444 - Cannot index built-in array with expression tuple
Summary: Cannot index built-in array with expression tuple
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: No Owner
URL:
Keywords: patch, spec
Depends on:
Blocks:
 
Reported: 2010-07-10 11:52 UTC by Shin Fujishiro
Modified: 2014-02-15 02:44 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Shin Fujishiro 2010-07-10 11:52:05 UTC
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; }
}
--------------------