On 08.08.2011 23:27, Christian Manning wrote:
Hi,
I'm receiving this error with dmd 2.054:
"tmp.d(7): Error: no [] operator overload for type Tuple!(int,short)" for
the following test case

import std.typecons;
void main() {
auto x = 1;
Tuple!(int,short) a;
a[0] = 1;
a[x] = 2;
}

If I use a value instead of a variable ie. a[1] = 2; it compiles fine.

A search turned up http://d.puremagic.com/issues/show_bug.cgi?id=6273 and
http://d.puremagic.com/issues/show_bug.cgi?id=6342 though they specifically
mention the use of pure functions which I'm not using. Is this the same
problem anyway?

Your case seems simple, it means you can't index tuple with variable as index, only with something known at compile time. Replace auto with enum and you are fine, you can even call a function using CTFE to get an index.

--
Dmitry Olshansky

Reply via email to