An int in a tuple cannot be used as an index for a tuple, even if it is completely determined at compile time.
---------------------------
// This doesn't work
template Nth(TList...) {
const int N = TList[0];
auto Nth = TList[N];
}
void main()
{
writefln( Nth!(1,"hi","there") );
}
-------------
In this case the sample can be fixed by using:
template Nth(int N, TList...) {
But that's not always the case.
Comment #1 by wbaxter — 2006-11-26T19:43:14Z
As of DMD 0.175 this can also be worked around by eliminating the N, and indexing directly with TList[0]:
template Nth(TList...) {
auto Nth = TList[TList[0]];
}
Comment #2 by wbaxter — 2006-12-17T02:37:13Z
Just retested with 0.177. This behavior is still there.
(I thought there was a chance it might have been fixed by the last two rounds of bug slaughters.)
Comment #3 by bugzilla — 2008-06-28T01:36:53Z
The example is broken because in order for the 'promotion' of the member Nth, it must be the only member. The following works:
import std.stdio;
template Nth(TList...) {
const int N = TList[0];
auto Nth = TList[N];
}
void main()
{
writefln( Nth!(1,"hi","there").Nth );
}
Comment #4 by wbaxter — 2008-06-28T02:48:43Z
(In reply to comment #3)
> The example is broken because in order for the 'promotion' of the member Nth,
> it must be the only member. The following works:
>
> import std.stdio;
>
> template Nth(TList...) {
> const int N = TList[0];
> auto Nth = TList[N];
> }
> void main()
> {
> writefln( Nth!(1,"hi","there").Nth );
> }
>
Good point. Or use the version I posted above without the intermediate variable. I blame the misunderstanding on my youth at the time of reporting this one. :-)