[Issue 11279] Error: no [] operator overload for type Tuple!(int, int, int)
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Oct 16 00:20:55 PDT 2013
http://d.puremagic.com/issues/show_bug.cgi?id=11279
monarchdodra at gmail.com changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
CC| |monarchdodra at gmail.com
Resolution| |INVALID
--- Comment #1 from monarchdodra at gmail.com 2013-10-16 00:20:53 PDT ---
for typetuple, operator[] is a "static" operator: The index *must* be known at
compile time, as the return type depends on the parameter. It's actually
different overloads for each different index:
EG:
auto a = tuple('a', 5, 2.2);
char c = a[0]; //Calls the first arg
int i = a[1]; //Calls the second arg
double d = a[2]; //Calls the last arg
Because of this putting an operator[] inside a for loop is not possible, as you
are basically trying to solve overloads dynamically, which is not possible in a
static language like D.
What could be a workaround for you is the static foreach construct:
void main(){
import std.typecons, std.typetuple;
auto a=tuple(0,1,2);
a[0]=0;//OK
foreach(I;TypeTuple!(0, 1, 2))
a[I]=0;//Error: no [] operator overload for type Tuple!(int, int, int)}
}
What this does is generate a "type sequence", which contains the "Types" (or in
this case, value parameters) 1, 2 and 3.
Now, the foreach is statically iterating over the parameters, generating a
*unique* body for each loop index. Notice that this time, I used the name "I"
this denotes that this argument is actually statically known inside the body of
the loop.
Closing as invalid.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list